7

写真: http: //img838.imageshack.us/img838/1402/picse.png

Picでレイアウトを作成するにはどうすればよいですか。2RelativeLayoutのみを使用します。以下は、最初のスクリーンショットのxmlレイアウトです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
<TextView
    android:id="@+id/timer_textview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_marginTop="10dip"
    android:textSize="30sp"
    android:layout_alignParentTop="true"
    android:text="@string/timer_start" />

<ListView 
    android:id="@+id/questions_listview"
    android:layout_below="@id/timer_textview"  
    android:layout_width="wrap_content"
    android:layout_height="fill_parent" />

<Button android:id="@+id/true_btn"
    android:text="@string/true_option"
    android:layout_alignParentBottom="true"
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/false_btn"
    android:text="@string/false_option"
    android:layout_toRightOf="@id/true_btn"
    android:layout_alignBaseline="@id/true_btn"
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
</RelativeLayout>
4

2 に答える 2

18

LinearLayoutこれを達成するために at bottom を使用できます。RelativeLayoutただし、レイアウトのみを使用したい場合:

<RelativeLayout android:layout_width="fill_parent" ... >

...    

<View android:id="@+id/helper" 
android:layout_width="0dp"
android:layout_height="0dp" 
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />

<Button android:id="@+id/true_btn"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:layout_toLeftOf="@id/helper"/>

<Button
android:id="@+id/false_btn"
android:layout_alignBaseline="@id/true_btn"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:layout_toRightOf="@id/helper" />

</RelativeLayout>

ネストされたレイアウトを本当に使用できないのですか?

于 2010-08-24T12:12:14.470 に答える
0

ボタンを

<Button android:id="@+id/true_btn"
    android:text="@string/true_option"
    android:layout_alignParentBottom="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/false_btn"
    android:text="@string/false_option"
    android:layout_toRightOf="@id/true_btn"
    android:layout_alignBaseline="@id/true_btn"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

false_btnは残りのスペースをすべて取得しますが、少なくとも全幅を使用します。

最初の幅を増やすにはtrue_btn、属性を設定できminWidthます-固定値を使用するか、画面幅を取得してminWidthその半分にします

于 2010-08-24T12:09:18.807 に答える