0

I was wondering how to use Relativelayout in order to make a tructure like this:

three buttons, let's call them A B and C; I want to put B and C one above the other and both of them on the right side of A as a single block matching the same width and height of A (so we'll have that B and C have half height of A but the same width).

Since I can't post images yet here you can find the image of what I'm looking for: http://img191.imageshack.us/img191/9765/stackg.jpg

The code I wrote about this part is this one:

<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>

The problem is that it's not going to scale with every screen because I had to set static sizes. I tried a lot of different solutions like using all the possible combinations for the layout_align and changing wrap_content even randomly but still, I can't fit them in the way I want them to without using static sizes.

4

3 回答 3

1

LinearLayout与 一起使用layout_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>
于 2013-04-18T11:54:47.163 回答
0

尝试这个,

<?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>
于 2013-04-18T12:02:34.117 回答
0

它应该如下所示

<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>

于 2013-04-18T12:03:49.267 回答