0

メインのアクティビティに下位ナビゲータが既に含まれているカスタムヘッダーを追加しようとしています。fragmentsのコンテナとして機能します。framelayout主なアクティビティのコンテンツをオーバーラップさせるフラグメントコンテナのレイアウト

以下のコードには、アプリケーションヘッダーとして機能するLinearlayout["@+id/application_header]が含まれていますが、ヘッダーはfragmentcontainer[@+id/main_container]がヘッダーと重なって表示されます。

プロパティandroid:layout_belowandroid:layout_aboveを試しましたが、依然として重複しています。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:design="http://schemas.android.com/apk/res-auto" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.amplitude.tron.volksradio.MainActivity"> 

<LinearLayout 
     android:id="@+id/application_header" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:orientation="horizontal" 
     android:gravity="center_horizontal"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="RADIO" 
      android:layout_gravity="center"/> 
    </LinearLayout> 

    <FrameLayout 
     android:id="@+id/main_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/application_header" 
     android:layout_above="@+id/bottomNavigationBar" 
     android:layout_alignParentTop="true"> 
    </FrameLayout> 

    <android.support.design.widget.BottomNavigationView 
     android:id="@+id/bottomNavigationBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     design:menu="@menu/bottom_menu_navigation" 
     android:background="#50b1b5b9"> 

    </android.support.design.widget.BottomNavigationView> 

</RelativeLayout> 

答えて

0

他の清潔な解決策があるかもしれませんが、実現可能であれば答えとして受け入れられます。

私はidを持つ要素の高さと同じであるandroid:layout_marginTop="50dp"を追加しました - これは、異なるサイズで画面に影響を与えるかどうかはわからないし、私の試験装置は、のみに5.5インチである@+id/application_header

PS-をソリューションは完璧に機能しました。

0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    <LinearLayout 
      android:id="@+id/application_header" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:orientation="horizontal" 
      android:gravity="center_horizontal"> 

    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="RADIO" 
      android:layout_gravity="center"/> 
    </LinearLayout> 

    <FrameLayout 
      android:id="@+id/main_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/application_header" 
      android:layout_above="@+id/bottomNavigationBar" 
      android:layout_alignParentTop="true"> 
    </FrameLayout> 

    <android.support.design.widget.BottomNavigationView 
      android:id="@+id/bottomNavigationBar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      design:menu="@menu/bottom_menu_navigation" 
      android:background="#50b1b5b9"> 
    </android.support.design.widget.BottomNavigationView> 
</LinearLayout> 
0

android:layout_belowRelativeLayoutandroid:layout_above作品。ちょうどTextViewLinearLayoutは冗長です。あなたはTextViewを使うことができます。これを行う方法に関するいくつかのオプションがあります。LinearLayout使用

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

    <LinearLayout 
     android:id="@+id/application_header" 
     android:layout_width="match_parent" 
     android:layout_height="50dp"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="RADIO"/> 
    </LinearLayout> 

    <FrameLayout 
     android:id="@+id/main_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/bottomNavigationBar" 
     android:layout_alignParentTop="true" 
     android:layout_below="@id/application_header"> 
    </FrameLayout> 

    <android.support.design.widget.BottomNavigationView 
     android:id="@+id/bottomNavigationBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:background="#50b1b5b9" 
     design:menu="@menu/bottom_menu_navigation"> 

    </android.support.design.widget.BottomNavigationView> 
</RelativeLayout> 

RelativeLayoutを使用

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

    <LinearLayout 
     android:id="@+id/application_header" 
     android:layout_width="match_parent" 
     android:layout_height="50dp"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="RADIO"/> 
    </LinearLayout> 

    <FrameLayout 
     android:id="@+id/main_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    </FrameLayout> 

    <android.support.design.widget.BottomNavigationView 
     android:id="@+id/bottomNavigationBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:background="#50b1b5b9" 
     design:menu="@menu/bottom_menu_navigation"> 

    </android.support.design.widget.BottomNavigationView> 
</LinearLayout> 

つ以上(よりよい)代替ToolbarCoordinatorLayoutを用いを次のようになります

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:design="http://schemas.android.com/tools"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay"/> 

    </android.support.design.widget.AppBarLayout> 

    <FrameLayout 
     android:id="@+id/main_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/application_header" 
     android:layout_above="@+id/bottomNavigationBar" 
     android:layout_alignParentTop="true" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

    <android.support.design.widget.BottomNavigationView 
     android:id="@+id/bottomNavigationBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     design:menu="@menu/bottom_menu_navigation" 
     android:background="#50b1b5b9"/> 

</android.support.design.widget.CoordinatorLayout> 
+0

を重ね、任意の量が少ない包みもパディングやマージンを追加

android:layout_centerInParent="true" 

、すでにそこにありますコード内の相対的なレイアウトだが、それは残念だが、画面外にナビゲーションメニューをプッシュした2番目のソリューションを試してみた。最後の解決策は私のタイトルがカスタムであるために探しているものではありません – IteratioN7T

+0

'Toolbar'ソリューションでは、依然としてカスタムビューを使用できます。 [references](https://developer.android.com/reference/android/support/v7/widget/Toolbar.html)から: "ツールバーには、次のオプション要素の組み合わせが含まれます:1つ以上のカスタムビュー。子ビューのToolbar.LayoutParamsがGravity値CENTER_HORIZONTALを示している場合、ビューはツールバーに残っている利用可能なスペース内に中央に配置しようと試みます他の要素が測定されています。 –

0

また、これを追加することで、画面のレイアウトアラインセンターを行うことができます努力に感謝

関連する問題