0

アプリのメイン画面のレイアウトがあります。これをEvernoteスタイルにします。これまでのところ、私のコードは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:gravity="center_vertical|center_horizontal"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|left"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button" />

        <ImageButton
            android:id="@+id/btn2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/btn3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button" />

        <ImageButton
            android:id="@+id/btn4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button" />
    </LinearLayout>

</LinearLayout>

これはどのように見えるかです:

ここに画像の説明を入力してください

そして、これは私がそれをどのように見せたいかです:

ここに画像の説明を入力してください

どうすればこれを達成できますか?このようにボタンをグループ化しますか?

よろしくお願いします!

4

2 に答える 2

1

ImageButtonの幅を0dpに設定し、layout_weightを1に設定する必要があります。さらにlayout_gravityをcenter_horizo​​ntalに設定します。

これにより、それらが適切に中央に配置されます。

よろしくお願いします、ティム

于 2012-04-24T08:11:48.620 に答える
1

あなたはこれにそれを適応させることができます、これはグーグルI/Oアプリからです。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:background="#ffffff">
<LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_weight="1" 
    android:padding="6dip">
    <LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:layout_weight="1">
        <Button android:id="@+id/button" 
            android:text="@string/button"
            android:drawableTop="@drawable/button" />
        <Button android:id="@+id/button" 
            android:text="@string/button"
            android:drawableTop="@drawable/button" />
    </LinearLayout>

    <LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:layout_weight="1">
        <Button android:id="@+id/button" 
            android:text="@string/button"
            android:drawableTop="@drawable/button" />
        <Button android:id="@+id/button" 
            android:text="@string/button"
            android:drawableTop="@drawable/button" />

    </LinearLayout>

    <LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:layout_weight="1">
        <Button android:id="@+id/button" 
            android:text="@string/button"
            android:drawableTop="@drawable/button" />
        <Button android:id="@+id/button" 
            android:text="@string/button"
            android:drawableTop="@drawable/button" />
    </LinearLayout>
</LinearLayout>

于 2012-04-24T08:16:03.970 に答える