Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
915 views
in Technique[技术] by (71.8m points)

xml - Take a Full Screenshot of ScrollView Android

Indeed, there are solutions and questions has been answered all over the SO. So, here is what I have tried so far!

Scroll_Layout.xml

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="0dp"
    android:layout_height="0dp"
    tools:layout_constraintTop_creator="1"
    tools:layout_constraintRight_creator="1"
    tools:layout_constraintBottom_creator="1"
    android:layout_marginStart="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    android:layout_marginEnd="8dp"
    app:layout_constraintRight_toRightOf="parent"
    android:layout_marginTop="8dp"
    tools:layout_constraintLeft_creator="1"
    android:layout_marginBottom="8dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <TextView
            android:id="@+id/txtAddress"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="ADDRESS"
            android:textSize="40px"
            android:textColor="@android:color/black"/>
        <EditText
            android:id="@+id/edtName"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="Enter Address"
            android:text="lorem emisidjsi damsodks"/>
        <TextView
            android:id="@+id/txtPostal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="POSTAL CODE"
            android:textSize="40px"
            android:layout_marginTop="10dp"
            android:textColor="@android:color/black"/>
        <EditText
            android:id="@+id/edtPostal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="Enter Postal Code"
            android:text="123456"/>

        <TextView
            android:id="@+id/txtCity"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="CITY / GNR"
            android:textColor="@android:color/black"
            android:textSize="40px" />

        <EditText
            android:id="@+id/edtCity"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Loresm"
            android:hint="Enter City"/>
        <TextView
            android:id="@+id/txtBnr"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="BNR"
            android:textSize="40px"
            android:layout_marginTop="10dp"
            android:textColor="@android:color/black"/>
        <EditText
            android:id="@+id/edtBnr"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="Enter BNR"
            android:text="1122"/>
        <TextView
            android:id="@+id/txtSize"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="SIZE"
            android:textSize="40px"
            android:layout_marginTop="10dp"
            android:textColor="@android:color/black"/>
        <EditText
            android:id="@+id/edtSize"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="Enter Size"
            android:text="50 x 400 x 200"/>
        <TextView
            android:id="@+id/txtRental"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="RENTAL"
            android:textSize="40px"
            android:layout_marginTop="10dp"
            android:textColor="@android:color/black"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="3"
            android:layout_marginTop="5dp"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">
                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:buttonTint="@color/colorPrimary"/>
                <TextView
                    android:id="@+id/txtFull"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Full"
                    android:textSize="40px"
                    android:layout_marginTop="10dp"
                    android:textColor="@android:color/black"
                    android:textAlignment="center"/>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">
                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:buttonTint="@color/colorPrimary"/>
                <TextView
                    android:id="@+id/txtPartial"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Partial"
                    android:textSize="40px"
                    android:layout_marginTop="10dp"
                    android:textColor="@android:color/black"
                    android:textAlignment="center"/>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">
                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:buttonTint="@color/colorPrimary"/>
                <TextView
                    android:id="@+id/txtRentalNo"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="No"
                    android:textSize="40px"
                    android:layout_marginTop="10dp"
                    android:textColor="@android:color/black"
                    android:textAlignment="center"/>

            </LinearLayout>

        </LinearLayout>

        <TextView
            android:id="@+id/txtBasement"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="BASEMENT"
            android:textSize="40px"
            android:layout_marginTop="10dp"
            android:textColor="@android:color/black"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="3"
            android:layout_marginTop="5dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">
                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:buttonTint="@color/colorPrimary" />
                <TextView
                    android:id="@+id/txtFurnished"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Furnished"
                    android:textSize="40px"
                    android:layout_marginTop="10dp"
                    android:textColor="@android:color/black"
                    android:textAlignment="center"/>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">
                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:buttonTint="@color/colorPrimary"/>
                <TextView
                    android:id="@+id/txtUnFurnished"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Un-Furnished"
                    android:textSize="40px"
                    android:layout_marginTop="10dp"
                    android:textColor="@android:color/black"
                    android:textAlignment="center"/>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">
                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:buttonTint="@color/colorPrimary"/>
                <TextView
                    android:id="@+id/txtBasementNo"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="No"
                    android:textSize="40px"
                    android:layout_marginTop="10dp"
                    android:textColor="@android:color/black"
                    android:textAlignment="center"/>

            </LinearLayout>
        </LinearLayout>

        <TextView
            android:id="@+id/txtType"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TYPE"
            android:textSize="40px"
            android:layout_marginTop="10dp"
            android:textColor="@android:color/black"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="3"
            android:layout_marginTop="5dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">
                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I hope this is work for you.. source here

Bitmap bitmap = getBitmapFromView(scrollview, scrollview.getChildAt(0).getHeight(), scrollview.getChildAt(0).getWidth());

//create bitmap from the ScrollView 
private Bitmap getBitmapFromView(View view, int height, int width) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null)
        bgDrawable.draw(canvas);
    else
        canvas.drawColor(Color.WHITE);
    view.draw(canvas);
    return bitmap;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...