1

XMLコードは次のとおりです。

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" android:layout_width="fill_parent">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    <TextView android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:text="Welcome"
        android:layout_centerInParent="true" android:textSize="20sp"/>
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    <TextView android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:text="Welcome"
        android:layout_centerInParent="true" android:textSize="20sp"/>
    </RelativeLayout>
</RelativeLayout>

それは実際にはシーンではありません(UIデザインはそのコードではありませんが、簡略化のために提示しています)。このコードから私が除いているのは、TextViewが互いに比較的(垂直方向に)表示されることです。好き:

                     Welcome
                     Welcome

ただし、代わりに出力は次のようになります。

                     Welcome

同様に、それらは互いにネストされ、互いに積み重ねられています。塗りつぶしの親として幅のレイアウトを作成したのに、なぜ他のレイアウトが下がらないのですか?最初のrelativelayoutをオーバーライドします。

レイアウトは2つ必要なので、1つだけ作成するように提案しないでください。

ありがとうございました。

4

2 に答える 2

2

レイアウトの関係を設定する必要があります。

以下で行った変更を試してください。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" android:layout_width="fill_parent">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:id="@+id/top_rel>
    <TextView android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:text="Welcome"
        android:layout_centerInParent="true" android:textSize="20sp"/>
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_below="@id/top_rel>
    <TextView android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:text="Welcome"
        android:layout_centerInParent="true" android:textSize="20sp"/>
    </RelativeLayout>
</RelativeLayout>

android:id="@+id/top_rel"識別を容易にするために、上部のレイアウトを指定しました。

また、を使用してビューの上部に配置するように指示しましたandroid:layout_alignParentTop="true"

下部RelativeLayoutは、を使用して上部の下に配置されていますandroid:layout_below="@id/top_rel"

于 2012-09-18T15:41:54.463 に答える
1

まず、最初のテキストビューに対応する相対レイアウトのIDを指定します。次に、idを使用して、2番目の相対レイアウトのlayout_belowプロパティを追加します。最初のテキストビューの下に表示されるようにします。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent">


 <RelativeLayout
        android:id = "@+id/first_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    <TextView android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:text="Welcome"
        android:layout_centerInParent="true" android:textSize="20sp"/>
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/first_layout">
    <TextView android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:text="Welcome"
        android:layout_centerInParent="true" android:textSize="20sp"/>
    </RelativeLayout>
</RelativeLayout>
于 2012-09-18T15:44:51.327 に答える