Android相对布局:一个按钮右侧两个按钮



我想知道如何使用Relativelayout,以使这样的结构:

三个按钮,我们称它们为A、B、C;我想把B和C放在另一个上面,它们都在A的右边,作为一个单独的块,匹配A的相同宽度和高度(所以我们会有B和C的高度是A的一半,但宽度相同)。

因为我还不能在这里发布图像,你可以找到我正在寻找的图像:http://img191.imageshack.us/img191/9765/stackg.jpg

我写的这部分代码是这样的:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/black"
    android:paddingLeft="16dp"
    android:paddingRight="16dp" >
    <Spinner
        android:id="@+id/A"
        android:layout_width="0dp"
        android:layout_height="96dp"
        android:layout_below="@id/another_block_that_fills_all_the_line"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/B" />
    <Spinner
        android:id="@id/B"
        android:layout_width="96dp"
        android:layout_height="48dp"
        android:layout_below="@id/another_block_that_fills_all_the_line"
        android:layout_alignParentRight="true" />
    <Spinner
        android:id="@id/C"
        android:layout_width="96dp"
        android:layout_height="48dp"
        android:layout_below="@id/B"
        android:layout_alignParentRight="true" />
</RelativeLayout>

问题是,它不会与每个屏幕缩放,因为我必须设置静态大小。我尝试了很多不同的解决方案,如使用所有可能的组合为layout_align和改变wrap_content甚至随机,但仍然,我不能适合他们的方式,我想他们没有使用静态大小

使用LinearLayoutlayout_weight。试试这个布局

<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:orientation="horizontal">
    <Button android:layout_width="0dip" android:layout_height="fill_parent"
        android:layout_weight="1.0"/>
    <LinearLayout android:layout_width="0dip" android:layout_height="fill_parent"
        android:layout_weight="1.0" android:orientation="vertical">
        <Button android:layout_width="fill_parent" android:layout_height="0dip"
            android:layout_weight="1.0"/>
        <Button android:layout_width="fill_parent" android:layout_height="0dip"
            android:layout_weight="1.0"/>
     </LinearLayout>
</LinearLayout>

试试这个,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black">
    <Button
        android:id="@+id/A"
        android:layout_width="wrap_content"
        android:layout_centerInParent="true"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/relativeLayout"
        android:layout_alignBottom="@+id/relativeLayout"
        android:text="AAA"/>
    <RelativeLayout
        android:id="@+id/relativeLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/A"
        android:layout_centerVertical="true"
        android:background="@android:color/black">
        <Button
            android:id="@+id/B"
            android:layout_width="wrap_content"
            android:text="BBB"
            android:layout_height="wrap_content"/>
        <Button
            android:id="@+id/C"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/B"
            android:text="CCC"/>
     </RelativeLayout>
</RelativeLayout>

应该如下所示

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:padding="10dp" >
<View
    android:id="@+id/helper"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />
<Spinner
    android:id="@+id/A"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_toLeftOf="@id/helper"
    android:background="@android:color/black" />
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/A"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@id/A"
    android:layout_marginLeft="10dp"
    android:layout_toRightOf="@id/helper"
    android:orientation="vertical" >
    <Spinner
        android:id="@+id/B"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginBottom="2dp"
        android:layout_weight="1"
        android:background="@android:color/black" />
    <Spinner
        android:id="@+id/C"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@android:color/black" />
</LinearLayout>

最新更新