2012-04-08 136 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"