在下面的图片中,黄色方块代表了我整体布局中的RelativeLayout。什么是合理的方式来使这种布局?
顶行“状态消息”是一个ViewFlipper,它响应用户可以按下的切换按钮(A,B)。按钮C,D和E执行重新加载整个视图的其他内容。我们的客户要求按照下面的方式排列按钮A,B,C,D和E. (垂直对齐不如水平对齐重要。)
编辑说,A,B,C,D和E是关于20x20倾角的图像;它们在约300dip的宽度内对齐。我想要按钮来保持它们的宽高比。
我创建的LinearLayout的扩展,膨胀(从XML文件)按钮A和B,然后另一的LinearLayout该膨胀在另一个XML文件按钮C,d,和E。
按钮A和B(实际上的ToggleButtons):
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="true"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
>
<ToggleButton
android:id="@+id/A"
android:textOn=""
android:textOff=""
android:background="@layout/A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_marginRight="30dp"
/>
<ToggleButton
android:id="@+id/B"
android:textOn=""
android:textOff=""
android:background="@layout/B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
/>
</LinearLayout>
</RelativeLayout>
按钮C,d,E xml文件:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="true"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
>
<ImageView
android:id="@+id/C"
android:src="@drawable/C"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
/>
<ImageView
android:id="@+id/D"
android:src="@drawable/D"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
/>
<ImageView
android:id="@+id/E"
android:src="@drawable/E"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
/>
</LinearLayout>
</RelativeLayout>
我的代码基本上是工作,但我有边距捏造使事情正确排列(他们还没有)。我不知道是否有中心对齐按钮集“A B”和“C d E”一些清洁的方式
PS:细心的读者会注意到,我伸出的LinearLayout,但充气RelativeLayouts。 (我不知道为什么它甚至可以工作,但是)当我尝试扩展RelativeLayout时,“C D E”布局甚至没有出现在我的设备上。我不知道它去了哪里。
如果OP想为按钮扩大,那么他需要与RelativeLayout的更换的LinearLayout,并结合layout_left/layout_right与利润等等。 – Audrius
我不想让按钮展开。我希望他们保持他们的相对大小,“漂浮”在他们给予的更大空间内。 –