2012-04-08 117 views
2

我想看看下面的佈置工作:我該如何解決這個RelativeLayout?

-------------------------- 
| -----------   | 
| |TextView1|   | 
| -----------   | 
| ---------------------- | 
| |EditText1   | | 
| ---------------------- | 
| -----------   | 
| |TextView2|   | 
| -----------   | 
| ---------------------- | 
| |EditText2   | | 
| ---------------------- | 
| -----------   | 
| |TextView3|   | 
| -----------   | 
| ---------------------- | 
| |     | | 
| |     | | 
| |     | | 
| |  ImageView  | | 
| |     | | 
| |     | | 
| |     | | 
| |--------------------| | 
| --------- -------- | 
| |Button1||Button2| | 
| --------- -------- | 
| ---------------------| | 
| |  ButtonBar  | | 
| ---------------------- | 
|------------------------| 

我的問題:我不能讓Button1的和Button2的工作在此佈局。它們要麼在ImageView下面,隱藏在ButtonBar的後面,要麼在ImageView的底部和ButtonBar的頂部之間收縮。

目前的XML代碼:

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

<RelativeLayout 
    android:id="@+id/relativeLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/footer" > 

    <TextView 
     android:id="@+id/textPostUser" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:text="user" /> 

    <EditText 
     android:id="@+id/editPostUser" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/textPostUser" 
     android:hint="user" 
     android:maxLength="40" > 

     <requestFocus /> 
    </EditText> 

    <TextView 
     android:id="@+id/textPostComment" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/editPostUser" 
     android:text="comment" /> 

    <EditText 
     android:id="@+id/editPostComment" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/textPostComment" 
     android:hint="comment" 
     android:maxLength="200" 
     android:maxLines="3" > 
    </EditText> 

    <TextView 
     android:id="@+id/textPostCharacterCount" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/editPostComment" 
     android:text="characters" 
     android:textSize="5pt" /> 

    <ImageView 
     android:id="@+id/imagePostResult" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@id/textPostCharacterCount" 
     android:src="@drawable/camera_icon" /> 

    <Button 
     android:id="@+id/buttonPostRotateLeft" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_below="@id/imagePostResult" 
     android:text="left" /> 

    <Button 
     android:id="@+id/buttonPostRotateRight" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_below="@id/imagePostResult" 
     android:layout_toRightOf="@id/buttonPostRotateLeft" 
     android:text="right" /> 
</RelativeLayout> 

<LinearLayout 
    android:id="@+id/footer" 
    style="@android:style/ButtonBar" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/buttonPostSave" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="save" /> 
</LinearLayout> 

</RelativeLayout> 

如何讓我的左/右按鈕出現在ImageView的下面和上面的按鈕欄? 我想至少在ImageView的高度/寬度上保持fill_parent,因爲它可以很好地在不同的分辨率下進行縮放。

+0

+1只爲你做了:) – Layke 2012-10-12 13:17:02

回答

1

你的ImageView設置爲FILL_PARENT以上,所以沒有留給下面的按鈕空間。

<Button 
     android:id="@+id/buttonPostRotateLeft" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:text="left" /> 

    <Button 
     android:id="@+id/buttonPostRotateRight" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_toRightOf="@id/buttonPostRotateLeft" 
     android:text="right" /> 

    <ImageView 
     android:id="@+id/imagePostResult" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/buttonPostRotateLeft" 
     android:layout_below="@id/textPostCharacterCount" 
     android:src="@drawable/camera_icon" /> 
+0

漂亮的格式這是完美的:這樣的ImageView通吃的剩餘空間時,按鈕已經包含可以轉換按鈕和ImageView的!接受的答案,我也學到了一些東西。 – 2012-04-08 13:44:08

1

爲什麼不把兩個按鈕放在水平LinearLayout中?

0

您的按鈕設置爲android:layout_alignParentBottom="true",以及線性佈局。後者會隱藏前者,因爲它在xml代碼中最後出現。

嘗試把你的按鈕以線性佈局,並將其對齊頁腳android:layout_above="@+id/footer"