レイアウトファイルから2つのチャンクを独立したレイアウトファイルに引っ張って再構成したい長いレイアウトファイルがあり、それをメインレイアウトファイルに含めます。Android:2つの異なるレイアウトがRelativeLayoutに含まれています
私の問題はinclude2
は正常RelativeLayout
行動のように右include1
の下に来るようにする方法です。 include
タグはlayout_above
とlayout_below
を認識しません。代わりにLinearLayout
を使用する解決方法がありますが、(メインレイアウトファイルの)画面の下部に付いているボタンは、その場所を保持できません。
メインレイアウトファイル:
<FrameLayout 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"
tools:context="com.stats.weekly.WeeklyStatsFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/include1"
layout="@layout/weekly_stats_header_view" />
<!-- Here I can't tell include2 to position itself under include1 -->
<include
android:id="@+id/include2"
layout="@layout/weekly_stats_content_view" />
<LinearLayout
android:id="@+id/statsButtonContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/statsButton"
style="@style/StandardButtonGreen"
android:layout_marginBottom="@dimen/material_horizontal_padding_half"
android:layout_marginLeft="@dimen/material_horizontal_padding_half"
android:layout_marginRight="@dimen/material_horizontal_padding_half"
android:layout_marginTop="@dimen/material_horizontal_padding_half"
android:elevation="2dp"
android:text="@string/strWeeklyStatsActivityButtonText" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
ソリューション更新:
:チラグとDipaliによって示唆されるように、私はそうLayout_above
とlayout_below
が関連するようになるlayout_width
とlayout_height
を追加しました
...
<include
android:id="@+id/include2"
layout="@layout/weekly_stats_content_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="@+id/weekly_stats_header_view"
android:layout_above="@+id/statsButtonContainer"/>
...
おかげチラグは、 'layout_below'も同じで、' layout_width'と 'layout_height'などが指定せずに動作しません。今はうまく動作します。 – Ambran
はい、正確にはこれらが必要です。 –