将卡片视图转换为图像(位图)

问题描述 投票:0回答:1

我有一个CardView布局,里面有一些视图。我想将CardView(其中包含所有视图)转换为图像。

检查XML:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MISC.IdentityCardActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/header"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:text="  "
                android:textColor="@color/blacko"
                android:textSize="18dp"
                android:textStyle="bold" />


            <androidx.cardview.widget.CardView
                android:id="@+id/cardfront"
                android:layout_width="390dp"
                android:layout_height="190dp"
                android:layout_below="@id/header"
                android:layout_centerHorizontal="true"
                android:layout_marginLeft="15dp"
                android:layout_marginTop="40dp"
                android:layout_marginRight="15dp"
                app:cardBackgroundColor="@color/ash"
                app:cardCornerRadius="10dp"
                app:cardElevation="8dp">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <ImageView
                        android:id="@+id/cardbackgorun"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:scaleType="centerCrop"
                        android:src="@drawable/jeep" />

                    <TextView
                        android:id="@+id/heading"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentTop="true"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="5dp"
                        android:fontFamily="@font/creditcard"
                        android:shadowColor="@color/text_shadow"
                        android:shadowDx="1"
                        android:shadowDy="1"
                        android:shadowRadius="10"
                        android:text=" RC IDENTITY CARD "
                        android:textColor="@color/white"
                        android:textSize="16dp" />


                    <TextView
                        android:id="@+id/uid"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/heading"
                        android:layout_centerInParent="true"
                        android:layout_marginTop="10dp"
                        android:fontFamily="@font/oswaldbold"
                        android:shadowColor="@color/text_shadow"
                        android:shadowDx="1"
                        android:shadowDy="1"
                        android:shadowRadius="10"
                        android:text="9C1bWbji49W613qVZowsQwMAOH32"
                        android:textColor="@color/white"
                        android:textSize="20dp" />

                    <LinearLayout
                        android:id="@+id/datesLL"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/uid"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="5dp"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/validfrom"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:fontFamily="@font/creditcard"
                            android:shadowColor="@color/text_shadow"
                            android:shadowDx="1"
                            android:shadowDy="1"
                            android:shadowRadius="10"
                            android:text="VALID FROM: "
                            android:textColor="@color/white"
                            android:textSize="10dp" />

                        <TextView
                            android:id="@+id/validfromdate"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:fontFamily="@font/creditcard"
                            android:shadowColor="@color/text_shadow"
                            android:shadowDx="1"
                            android:shadowDy="1"
                            android:shadowRadius="10"
                            android:text="11/23           "
                            android:textColor="@color/white"
                            android:textSize="10dp" />

                        <TextView
                            android:id="@+id/validthru"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:fontFamily="@font/creditcard"
                            android:shadowColor="@color/text_shadow"
                            android:shadowDx="1"
                            android:shadowDy="1"
                            android:shadowRadius="10"
                            android:text="VALID THRU: "
                            android:textColor="@color/white"
                            android:textSize="10dp" />

                        <TextView
                            android:id="@+id/validthrudate"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:fontFamily="@font/creditcard"
                            android:shadowColor="@color/text_shadow"
                            android:shadowDx="1"
                            android:shadowDy="1"
                            android:shadowRadius="10"
                            android:text="11/35"
                            android:textColor="@color/white"
                            android:textSize="10dp" />
                    </LinearLayout>

                    <RelativeLayout
                        android:id="@+id/userRL"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/datesLL"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="12dp"
                        android:layout_marginBottom="8dp">


                        <de.hdodenhof.circleimageview.CircleImageView
                            android:id="@+id/userimage"
                            android:layout_width="90dp"
                            android:layout_height="90dp"
                            android:layout_centerVertical="true"
                            android:src="@drawable/def" />

                        <RelativeLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:layout_marginLeft="10dp"
                            android:layout_toRightOf="@id/userimage">

                            <TextView
                                android:id="@+id/username"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:ellipsize="end"
                                android:fontFamily="@font/creditcard"
                                android:maxLines="1"
                                android:shadowColor="@color/text_shadow"
                                android:shadowDx="1"
                                android:shadowDy="1"
                                android:shadowRadius="10"
                                android:text="NITHEESH AG"
                                android:textColor="@color/white" />

                            <TextView
                                android:id="@+id/rides"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_below="@id/username"
                                android:fontFamily="@font/creditcard"
                                android:shadowColor="@color/text_shadow"
                                android:shadowDx="1"
                                android:shadowDy="1"
                                android:shadowRadius="10"
                                android:text="RIDES"
                                android:textColor="@color/white" />

                            <TextView
                                android:id="@+id/vehiclemake"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_below="@id/rides"
                                android:ellipsize="end"
                                android:fontFamily="@font/creditcard"
                                android:maxLines="1"
                                android:shadowColor="@color/text_shadow"
                                android:shadowDx="1"
                                android:shadowDy="1"
                                android:shadowRadius="10"
                                android:text="HONDA"
                                android:textColor="@color/white" />

                            <TextView
                                android:id="@+id/vehiclemodel"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_below="@id/vehiclemake"
                                android:ellipsize="end"
                                android:fontFamily="@font/creditcard"
                                android:maxLines="1"
                                android:shadowColor="@color/text_shadow"
                                android:shadowDx="1"
                                android:shadowDy="1"
                                android:shadowRadius="10"
                                android:text="CBR 150R"
                                android:textColor="@color/white" />
                        </RelativeLayout>
                    </RelativeLayout>


                </RelativeLayout>


            </androidx.cardview.widget.CardView>


            <ImageView
                android:id="@+id/dummy"
                android:layout_width="300dp"
                android:layout_height="200dp"
                android:layout_below="@id/cardfront"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="30dp"
                android:scaleType="centerCrop" />

        </RelativeLayout>
    </ScrollView>


</androidx.constraintlayout.widget.ConstraintLayout>
  • 此布局是用于演示目的的虚拟布局。

这里,CardView cardfront,我想将其转换为图像位图,并希望在ImageView dummy中显示它。

我检查了很多,但是都没有用。那些也被折旧了。有什么新的方法可以实现它。

(image)this layout to an image

java android canvas bitmap cardview
1个回答
0
投票

我希望您尝试将视图转换为位图,如果没有,请在下面的代码段中尝试一下,并将位图设置为转换为dummy

© www.soinside.com 2019 - 2024. All rights reserved.