1

レイアウトに取り組んでいます。temp1はtemp2に含まれています。temp1は正常に機能していますが、これをtemp2に含めると。temp1のルートがfill_parentに設定されているため、画面全体に表示されます。この場合の解決策は何でしょうか?

中央のtemp2の小さな領域にtemp1のレイアウトを表示したいと思います。

temp1.xml

<RelativeLayout android:layout_height="fill_parent"
                 android:layout_width="fill_parent">


</RelativeLayout>

temp2.​​xml

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


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:id="@+id/relativeLayout">
    <include
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            layout="@layout/temp1"/>
</RelativeLayout>

</RelativeLayout>
4

1 に答える 1

1

layout_*含めるレイアウトのルートビューのフィールドをオーバーライドできます。この場合、フィールドはのルートをオーバーライドRelativeLayoutします@layout/temp1

マージンを使用して、必要な境界線の量に調整できます(これ100dpは単なる例です)。

<include
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="100dp"
        layout="@layout/temp1"/>

または、必要なサイズを設定できます(これ100dpは単なる例です)。

<include
        android:layout_width="100dp"
        android:layout_height="100dp"
        layout="@layout/temp1"/>

または、そこにあるコンテンツを表示することもできます(temp1現時点では何もありません)。

<include
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        layout="@layout/temp1"/>

詳細については、 http://developer.android.com/training/improving-layouts/reusing-layouts.htmlを参照してください。

于 2013-03-14T22:08:04.770 に答える