Android从xml布局获取Main Relativelayout的图像?

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

我有xml文件,并创建视图,我在下一个活动中传递该屏幕截图。还有主要布局的图像。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent" android:id="@+id/mainLayout"
    android:layout_height="match_parent">

    <ImageView android:layout_height="wrap_content" android:id="@+id/imageSelected"
        android:src="@drawable/icon" android:layout_width="wrap_content"
        android:layout_centerVertical="true" android:layout_alignParentLeft="true"
        android:layout_marginLeft="79dp"></ImageView>

    <RelativeLayout android:layout_width="fill_parent"
        android:id="@+id/relativelayoutfinal" android:layout_height="fill_parent">
    </RelativeLayout>

    <RelativeLayout android:id="@+id/RelativeLayoutbutton"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
        <include layout="@layout/bottombutton" />
    </RelativeLayout>

    <Button android:layout_width="wrap_content" android:background="@drawable/b_brightness_contrast"
        android:id="@+id/btnbrightcont" android:layout_height="wrap_content"
        android:layout_marginBottom="40dip" android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true" android:layout_marginRight="103dp"></Button>
    <Button android:background="@drawable/b_adjust_and_scale"
        android:layout_width="wrap_content" android:id="@+id/btnadjustscale"
        android:layout_above="@+id/btnbrightcont" android:layout_alignLeft="@+id/btnbrightcont"
        android:layout_height="wrap_content"></Button>

    <SeekBar android:layout_height="wrap_content" android:progress="50"
        android:layout_marginTop="50dip" android:layout_marginRight="30dip"
        android:layout_width="160dip" android:id="@+id/sbbrightness"
        android:visibility="gone" android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"></SeekBar>
    <SeekBar android:layout_height="wrap_content" android:progress="50"
        android:visibility="gone" android:layout_width="160dip" android:id="@+id/sbcontrast"
        android:layout_below="@+id/sbbrightness" android:layout_alignLeft="@+id/sbbrightness"></SeekBar>
</RelativeLayout>

并将图像作为drawable或bitmap发送到下一个活动......它可能??

android
1个回答
10
投票

据我所知,你想要你的relativelayout xml的屏幕截图:

为此您可以使用:

 View v = yourrelativelayout.getRootView();
             v.setDrawingCacheEnabled(true);
             Bitmap bitmap = v.getDrawingCache();
             BitmapDrawable drawable=new BitmapDrawable(bitmap);

您可以将此BitmapDrawable用作Drawable,并可以传递给下一个活动。

希望能帮助到你。

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