-1

私はそれぞれの中に3layoutつある4つの水平を含むを持っています。LinearLayoutsImageButtons

要素を追加する必要があり、を使用する必要があるため、これらLinearLayoutをに変換したいと思います。RelativeLayouttoRightOfalignParentTop

この変更を行うために使用しているコードは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:background="@drawable/bugbox_wall_port" >
    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical" >
        <Button
            android:id="@+id/writeNewMsg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="New" />
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:padding="10dp" >
            <ImageButton
                android:id="@+id/spyMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/msgspy" />
            <ImageButton
                android:id="@+id/playerMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@drawable/msgplyr"
                android:layout_toRightOf="@id/spyMsgs" />
            <ImageButton
                android:id="@+id/allyMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/msgally"
                android:layout_toRightOf="@id/playerMsgs" />
        </RelativeLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:padding="10dp" >
            <ImageButton
                android:id="@+id/battleMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/msgbatt" />
            <ImageButton
                android:id="@+id/skynetMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@drawable/msgnet" />
            <ImageButton
                android:id="@+id/transportMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/msgtrans" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:padding="10dp" >
            <ImageButton
                android:id="@+id/expeditionMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/msgexp" />
            <ImageButton
                android:id="@+id/newsMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@drawable/msgnews" />
            <ImageButton
                android:id="@+id/buildingMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/msgbuild" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:padding="10dp" >
            <ImageButton
                android:id="@+id/allMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/msgall" />
            <ImageButton
                android:id="@+id/binMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:background="@drawable/msgbin" />
        </LinearLayout>
    </LinearLayout>
</ScrollView>

しかし、理由はわかりませんRelativeLayout。問題があります。

これが私の問題であるグラフィカルに説明する画像です:

http://img811.imageshack.us/img811/5479/stackes.jpg

それは私を狂わせています。なぜこれが起こっているのか分かりません。以前にRelativesLayoutを使用しましたが、問題はありませんでした。

だから私の質問は:なぜこれが起こっているのですか?次に、このエラーを修正するにはどうすればよいですか?

前もって感謝します!

4

2 に答える 2

0

解決しました。プログラムでビューにIDを設定していましたが、気づきませんでした...

于 2012-08-06T13:50:11.387 に答える
0

これを試してみてください。一番下の線形レイアウトをコメントアウトしました。相対レイアウトが思いどおりに機能する場合は、それに応じて他の線形を調整できます。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:background="@drawable/bugbox_wall_port" >
    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical" >
        <Button
            android:id="@+id/writeNewMsg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="New" />
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="10dp" >
            <ImageButton
                android:id="@+id/spyMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_launcher" />
            <ImageButton
                android:id="@+id/playerMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@drawable/ic_launcher"
                android:layout_toRightOf="@id/spyMsgs" />
            <ImageButton
                android:id="@+id/allyMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_launcher"
                android:layout_toRightOf="@id/playerMsgs" />
        </RelativeLayout>
        <!-- <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:padding="10dp" >
            <ImageButton
                android:id="@+id/battleMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/msgbatt" />
            <ImageButton
                android:id="@+id/skynetMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@drawable/msgnet" />
            <ImageButton
                android:id="@+id/transportMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/msgtrans" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:padding="10dp" >
            <ImageButton
                android:id="@+id/expeditionMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/msgexp" />
            <ImageButton
                android:id="@+id/newsMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@drawable/msgnews" />
            <ImageButton
                android:id="@+id/buildingMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/msgbuild" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:padding="10dp" >
            <ImageButton
                android:id="@+id/allMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/msgall" />
            <ImageButton
                android:id="@+id/binMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:background="@drawable/msgbin" />
        </LinearLayout> -->
    </LinearLayout>
</ScrollView>
于 2012-08-01T16:38:52.717 に答える