2011-02-15 138 views
0

Hy!如何調整圖片的大小?

我在視圖上有兩張圖片,在按鈕上有一個按鈕。

Screenshot

XML:

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> 
    <TextView android:layout_height="wrap_content" android:id="@+id/mainscreen" android:layout_width="fill_parent" android:text="Selected Channel" android:gravity="center" android:layout_alignParentTop="true"></TextView> 
    <ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> 
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/mainscreen_state" android:layout_above="@+id/mainscreen_btchange"></TextView> 
    <ImageView android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:layout_height="wrap_content" android:id="@+id/ImageAd" android:layout_gravity="center" android:layout_below="@+id/mainscreen"></ImageView> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent"> 


    <Button android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:id="@+id/mainscreen_btchange" 
     android:text="Change State"></Button> 


    </RelativeLayout> 
    </LinearLayout> 

我的問題:如何收縮,佈局的所有元素都顯示的圖片?

回答

1

對於更復雜的佈局,我需要確保一堆物品都可以顯示,我通常以RelativeLayout作爲最外層的容器。我使用layout_alignParentTop和layout_alignParentBottom(在垂直佈局的情況下,你似乎是這樣)停靠任何需要在肢體上的需求,然後我努力使下一組元素與它們相關。基本上,從邊緣開始,工作你的方式。

所以,在你的情況下,按鈕應該有屬性android:layout_alignParentBottom="true",和電視應該有android:layout_above="@+id/mainscreen_btchange"。頂部的TextView的應有android:layout_alignParentTop="true"和其下方的Im​​ageView應該有android:layout_below="@+id/mainscreen"

+0

錯誤:未發現在包「機器人」屬性「layout_alignBelow」資源標識符 – user547995 2011-02-15 16:33:47