0

これに似た質問を見たことがあります。ただし、これらのシナリオは異なり、一部は初心者向けではありません。
ということで、最近Androidを始めました。私がに慣れていないことを理解してください*.xml。とにかく、私の懸念はLinearLayout、最初の のみを表示する入れ子に関するものViewです。

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="horizontal">

        <TextView
            android:layout_gravity="center"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:textSize="20sp"
            android:text="@string/app_title">
        </TextView>

    </LinearLayout>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="horizontal">

        <Button 
            android:layout_gravity="center"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="@string/button_ok"
            android:onClick="changeMessage">
        </Button>

        <TextView
            android:layout_gravity="center"
            android:textSize="20sp"
            android:id="@+id/this_text"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="@string/sample_text">
        </TextView>

    </LinearLayout>

</LinearLayout>

これまでの XML は次のとおりです。このコードでは、最初の TextView のみが表示されます。

4

3 に答える 3

2

android:layout_height="match_parent"入れ子の高さは、LinearLayout代わりwrap_contentmatch_parent

于 2013-01-10T08:31:17.737 に答える
1

最初のLinearLayout幅と高さを指定したためmatchparent

高さを次のように変更しますwrapcontent

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:orientation="horizontal">

    <TextView
        android:layout_gravity="center"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:textSize="20sp"
        android:text="@string/app_title">
    </TextView>

</LinearLayout>

// other layouts
于 2013-01-10T08:31:31.693 に答える
1

以下のようにレイアウトを変更します

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_gravity="center"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:textSize="20sp"
        android:text="@string/app_title">
    </TextView>

</LinearLayout>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:orientation="horizontal">

    <Button 
        android:layout_gravity="center"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="@string/button_ok"
        android:onClick="changeMessage">
    </Button>

    <TextView
        android:layout_gravity="center"
        android:textSize="20sp"
        android:id="@+id/this_text"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="@string/sample_text">
    </TextView>

</LinearLayout>

内部レイアウトは親レイアウトと一致しているため、最初のレイアウトのみが表示されます。

于 2013-01-10T08:31:57.990 に答える