-1

相対リンクを使用してボタンを表示するのに問題があるようです。ボタン同士が重なり合うようにくっつきます。くっつかないようにしようとしましたが、無駄でした。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:background="@drawable/formation"
android:layout_height="fill_parent" >

<Button
    android:layout_weight="1.0"
    android:layout_gravity="bottom"
    android:layout_alignParentTop="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/Laws" />
<Button 
    android:layout_weight="1.0"
    android:layout_gravity="bottom"
    android:layout_alignParentTop="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Qualifications of a naval officer" />
<Button
    android:layout_weight="1.0" 
    android:layout_gravity="bottom"
    android:layout_alignParentTop="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Code of Conduct" />
</RelativeLayout>
4

4 に答える 4

1

xml ファイルを作成する際は、すべてのウィジェットが ID によって一意であることを念頭に置いてください。そのため、まず各ウィジェットに ID を割り当てる必要があります。

さて、ここでは相対レイアウトを使用しています。ここに追加したすべてのウィジェットは相互に関連付けられます。

このコードを参照してください。コードを変更しました。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="fill_parent"
   android:background="@drawable/formation"
   android:layout_height="fill_parent" >

<Button
android:id="@+id/btn1"
android:layout_weight="1.0"
android:layout_gravity="bottom"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Laws" />
<Button 
android:id="@+id/btn2"
android:layout_gravity="bottom"
android:layout_below="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Qualifications of a naval officer" />
<Button
android:id="@+id/btn3"
android:layout_gravity="bottom"
android:layout_below="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Code of Conduct" />
</RelativeLayout>

したがって、すべてのボタンが 1 つずつ表示されます。

于 2012-10-12T05:20:36.547 に答える
0

これにより、物事が他の側面の隣に置かれます。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:background="@drawable/formation"
android:layout_height="fill_parent" >

<Button
    android:id="@+id/button1"
    android:layout_weight="1.0"
    android:layout_gravity="bottom"
    android:layout_alignParentTop="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/Laws" />
<Button 
    android:id="@+id/button2"
    android:layout_toRightOf="@id/button1"
    android:layout_weight="1.0"
    android:layout_gravity="bottom"
    android:layout_alignParentTop="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Qualifications of a naval officer" />
<Button
    android:id="@+id/button3"
    android:layout_toRightOf="@id/button2"
    android:layout_weight="1.0" 
    android:layout_gravity="bottom"
    android:layout_alignParentTop="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Code of Conduct" />
</RelativeLayout>
于 2012-10-12T05:06:05.203 に答える
0

これを試して

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@drawable/formation" >

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_gravity="bottom"
                android:text="@string/Laws"  />

            <Button
                android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_gravity="bottom"
                android:layout_toRightOf="@+id/button1"
                android:text="Code of Conduct" />

            <Button
                android:id="@+id/button3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_toRightOf="@+id/button2"
                android:text="Qualifications of a naval officer" />

        </RelativeLayout>
于 2012-10-12T05:09:03.037 に答える
0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white" >

<Button
    android:id="@+id/btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Laws" />

<Button
    android:id="@+id/btn2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/btn1"
    android:text="Code of Conduct" />

<Button
    android:id="@+id/btn3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/btn2"
    android:text="Qualifications of a naval officer" />
</RelativeLayout>
于 2012-10-12T05:16:47.200 に答える