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);
我尝试了三种方法-
但使用这种方法,我的布局会缩小和重叠 宽度为1107,高度为448 我使用Framelayout作为内部视图的根布局和相对布局
qr_sheetview.post(new Runnable() {
@Override
public void run() {
sharedbmap = loadBitmapFromView(qr_sheetview);
shareBitmap(adjustOpacity(sharedbmap), "temporary");
}
});
<?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 aFrameLayout
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>