2016-08-29 3 views
0

レイアウトファイルから2つのチャンクを独立したレイアウトファイルに引っ張って再構成したい長いレイアウトファイルがあり、それをメインレイアウトファイルに含めます。Android:2つの異なるレイアウトがRelativeLayoutに含まれています

私の問題はinclude2は正常RelativeLayout行動のように右include1の下に来るようにする方法です。 includeタグはlayout_abovelayout_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_abovelayout_belowが関連するようになるlayout_widthlayout_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"/> 
... 

答えて

0

使用を含む、あなたがリニアレイアウトで使用したい場合は、次に重量を使用して1:

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

    <include 
     android:id="@+id/include1" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:layout_alignParentTop="true" 
     layout="@layout/weekly_stats_header_view" /> 

    <!-- Here I can't tell include2 to position itself under include1 --> 
    <include 
     android:id="@+id/include2" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:layout_below="@+id/include1" 
     layout="@layout/weekly_stats_content_view" /> 

    <LinearLayout 
     android:id="@+id/statsButtonContainer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/include2"> 

     <Button 
      android:id="@+id/statsButton" 
      android:elevation="2dp" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="test" /> 

    </LinearLayout> 

</RelativeLayout> 
+0

おかげチラグは、 'layout_below'も同じで、' layout_width'と 'layout_height'などが指定せずに動作しません。今はうまく動作します。 – Ambran

+0

はい、正確にはこれらが必要です。 –

0

IncludeとRelativeLayoutの内側にあるボタンでLinearLayoutを使用するだけです。 または2 LinearLayouts - 、相対的なレイアウトでそのような別のボタンで

0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relative_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <include 
     android:id="@+id/include1" 
     layout="@layout/demo1" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" /> 

    <include 
     android:id="@+id/include2" 
     layout="@layout/demo2" 
     android:layout_below="@+id/include1" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"/> 

    <LinearLayout 
     android:id="@+id/statsButtonContainer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="Button"/> 

    </LinearLayout> 

</RelativeLayout> 
+0

必要なもの: 'android:layout_below =" @ + id/relative_layout "'? – Shaishav

1

だけ追加するにはXMLを使用およびlayout_heightlayout_belowのプロパティはinclude2にあります。

<include 
       android:id="@+id/include2" 
       layout_below = "@+id/include1" 
       layout_width = "match_parent" 
       layout_height = wrap_content" 
       layout="@layout/weekly_stats_content_view" /> 
関連する問題