2011-11-02 27 views
2

我有XML文件,並創建視圖,我通過該屏幕截圖在下一activity.and也有主版面的圖像。Android從xml佈局獲取Main Relativelayout的圖像?

<?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或位圖到下一個活動...它的可能??

回答

10

據我瞭解,您希望您的RelativeLayout XML的屏幕截圖:

爲此,您可以使用:

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

您可以使用此BitmapDrawable作爲繪製對象,並能傳遞到下一個活動。

希望它有幫助。

+0

thanx這麼多...你是絕對正確的...... –

+0

但是當我通過bitmapdrawable到其他活動可以設置填充父視圖和視圖不一樣這個視圖/// –

+0

這意味着當你使用這個bitmapdrawable ,你可以使用fillparent和setbackground的佈局,所以它來全屏幕..你問? – Udaykiran