Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将膨胀的布局转换为位图_Android_Android Layout_Bitmap - Fatal编程技术网

Android 将膨胀的布局转换为位图

Android 将膨胀的布局转换为位图,android,android-layout,bitmap,Android,Android Layout,Bitmap,我正在膨胀一个布局并将其转换为,然后我将使用通常的意图来共享它 使用- LayoutInflater inflater2 = LayoutInflater.from(this); qr_sheetview = inflater2.inflate(R.layout.dummy_layout, mainlayout, false); 我尝试了三种方法- 使用此方法将膨胀视图转换为位图 qr_sheetview.setDrawingCacheEnabled(真); qr_sheet

我正在膨胀一个布局并将其转换为,然后我将使用通常的意图来共享它

使用-

LayoutInflater inflater2 = LayoutInflater.from(this);

        qr_sheetview = inflater2.inflate(R.layout.dummy_layout, mainlayout, false);
我尝试了三种方法-

  • 使用此方法将膨胀视图转换为位图
  • qr_sheetview.setDrawingCacheEnabled(真); qr_sheetview.measure(视图。测量规格。MakeMasureSpec(0, 视图。测量值(未指定), View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED)); qr_sheetview.layout(0,0,qr_sheetview.getMeasuredWidth(),qr_sheetview.getMeasuredHeight()); qr_sheetview.buildDrawingCache(true); sharedmap=Bitmap.createBitmap(qr_sheetview.getDrawingCache())


    但使用这种方法,我的布局会缩小和重叠

    宽度为1107,高度为448

    我使用Framelayout作为内部视图的根布局和相对布局

  • 我使用的第二种方法是->

    sharedmap=Bitmap.createBitmap(qr_sheetview.getWidth()、qr_sheetview.getHeight()、Bitmap.Config.ARGB_8888); 画布=新画布(sharedbmap); qr_sheetview.draw(画布)

  • 在此方法中发生错误:高度和宽度必须大于0

    使用它也会给我同样的错误

    qr_sheetview.post(new Runnable() {
                        @Override
                        public void run() {
    
                            sharedbmap = loadBitmapFromView(qr_sheetview);
    
                            shareBitmap(adjustOpacity(sharedbmap), "temporary");
    
                        }
                    });
    
  • 第三种方法是->

    公共静态位图loadBitmapFromView(视图v){

  • 在这方面,我得到了与第一次相同的结果

    布局为->

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        >
    
        <RelativeLayout
            android:id="@+id/mainqrlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ffffff">
    
            <RelativeLayout
                android:id="@+id/layout001"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp">
    
                <TextView
                    android:id="@+id/appname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:gravity="center|bottom"
                    android:text="Some text"
                    android:textColor="#212121"
                    android:textStyle="bold"
                    android:textSize="24sp" />
    
                <ImageView
                    android:id="@+id/logo"
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:layout_centerHorizontal="true"
                    android:layout_below="@+id/appname"
                    android:layout_marginTop="10dp"
                    android:src="@drawable/logomain" />
    
    
            </RelativeLayout>
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@+id/layout003"
                android:layout_below="@+id/layout001">
    
                <ImageView
                    android:id="@+id/qrimage"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true" />
    
                <ProgressBar
                    android:id="@+id/progressBar"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_centerInParent="true"
                    android:visibility="gone" />
    
                <ImageView
                    android:id="@+id/qr_logo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:visibility="gone"
                    card_view:srcCompat="@drawable/kj_qr_logo_svg" />
    
    
    
    
            </RelativeLayout>
    
            <RelativeLayout
                android:id="@+id/layout003"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true">
    
                <TextView
                    android:id="@+id/vpaname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:gravity="center"
                    android:text="kdvkjadsfkasmd"
                    android:textColor="#212121" />
    
                <TextView
                    android:id="@+id/qr_vpa"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/vpaname"
                    android:layout_centerHorizontal="true"
                    android:text="skdmfkjasdf"
                    android:textColor="#444444" />
    
                <TextView
                    android:id="@+id/text3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/qr_vpa"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="15dp"
                    android:gravity="center"
                    android:padding="10dp"
                    android:text="ckasfdowmdmwkmdwkdmkwmdklmekld \n sdafasdfasdfaasdf"
                    android:textColor="#727272" />
    
                <TextView
                    android:id="@+id/companyname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/text3"
                    android:layout_centerHorizontal="true"
                    android:layout_marginBottom="10dp"
                    android:layout_marginTop="20dp"
                    android:gravity="bottom"
                    android:text="@string/companyname"
                    android:textColor="#727272"
                    android:textSize="10sp" />
    
            </RelativeLayout>
    
        </RelativeLayout>
    </FrameLayout>
    
    
    
    “但是,使用这个方法,我的布局会缩小和重叠”——大概是你的布局出现了问题。你可能会考虑发布布局和你使用的代码来膨胀那个布局。确保你的布局的根不是<代码> RealValayOut(使用其他的东西)。.顺便说一句,在你的技巧中,#3似乎最接近我要尝试的。为什么不使用相对布局我的意思是以前我使用线性布局,结果是理想的。但是由于我的布局有点复杂,我认为相对布局对我来说是最好的。我如何使用相对布局将
    相对布局
    包装在其他东西中,李ke a
    FrameLayout
    RelativeLayout
    只有在它知道其父容器是什么时才起作用。我已经添加了布局…请帮助…我还添加了如何扩展布局
    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        >
    
        <RelativeLayout
            android:id="@+id/mainqrlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ffffff">
    
            <RelativeLayout
                android:id="@+id/layout001"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp">
    
                <TextView
                    android:id="@+id/appname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:gravity="center|bottom"
                    android:text="Some text"
                    android:textColor="#212121"
                    android:textStyle="bold"
                    android:textSize="24sp" />
    
                <ImageView
                    android:id="@+id/logo"
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:layout_centerHorizontal="true"
                    android:layout_below="@+id/appname"
                    android:layout_marginTop="10dp"
                    android:src="@drawable/logomain" />
    
    
            </RelativeLayout>
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@+id/layout003"
                android:layout_below="@+id/layout001">
    
                <ImageView
                    android:id="@+id/qrimage"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true" />
    
                <ProgressBar
                    android:id="@+id/progressBar"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_centerInParent="true"
                    android:visibility="gone" />
    
                <ImageView
                    android:id="@+id/qr_logo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:visibility="gone"
                    card_view:srcCompat="@drawable/kj_qr_logo_svg" />
    
    
    
    
            </RelativeLayout>
    
            <RelativeLayout
                android:id="@+id/layout003"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true">
    
                <TextView
                    android:id="@+id/vpaname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:gravity="center"
                    android:text="kdvkjadsfkasmd"
                    android:textColor="#212121" />
    
                <TextView
                    android:id="@+id/qr_vpa"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/vpaname"
                    android:layout_centerHorizontal="true"
                    android:text="skdmfkjasdf"
                    android:textColor="#444444" />
    
                <TextView
                    android:id="@+id/text3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/qr_vpa"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="15dp"
                    android:gravity="center"
                    android:padding="10dp"
                    android:text="ckasfdowmdmwkmdwkdmkwmdklmekld \n sdafasdfasdfaasdf"
                    android:textColor="#727272" />
    
                <TextView
                    android:id="@+id/companyname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/text3"
                    android:layout_centerHorizontal="true"
                    android:layout_marginBottom="10dp"
                    android:layout_marginTop="20dp"
                    android:gravity="bottom"
                    android:text="@string/companyname"
                    android:textColor="#727272"
                    android:textSize="10sp" />
    
            </RelativeLayout>
    
        </RelativeLayout>
    </FrameLayout>