2016-01-23 46 views
0

當我在我的RecyclerView上設置背景參數時,它隱藏了工具欄。設置Recycleviewer背景時隱藏工具欄

很簡單,但我無法弄清楚如何解決它。

activity_main.xml中:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:background="@android:color/darker_gray" 
    tools:context="los.printers.MainActivity" 
    app:theme="@style/Theme.MyTheme"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/tb_main" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:minHeight="?attr/actionBarSize" 
     android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

    <RelativeLayout 
     android:id="@+id/rl_fragment_container" 
     android:layout_alignParentTop="true" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</RelativeLayout> 

fragment_printer.xml

<?xml version="1.0" encoding="utf-8"?> 
<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="los.printers.fragment_printer"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/rv_List" 
     android:scrollbars="vertical" 
     android:paddingTop="?attr/actionBarSize" 
     android:background="@color/colorTextIcons" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

</FrameLayout> 

的填充在RecyclerView工作正常,但工具欄不顯示了。

+0

使recylerview在工具欄下方並刪除android:layout_alignParentTop =「true」line看到下面的答案 –

回答

0

rl_fragment_container繪製在工具欄的頂部。

但我想你知道,因爲你在你的片段中應用填充。

A 填充將繪製相同大小的視圖並應用於其內容,而邊距將在視圖邊界之外,從而使整個視圖更小。如果您繪製背景,這很重要。

如上所述,您的片段位於工具欄頂部,您的recyclerview將填充整個片段並在頂部繪製背景。

現在,您可以

  1. 招工具欄中的XML之前rl_fragment_container- >這將會把它繪製工具欄下方
  2. 改變填充保證金
  3. 或只是佈局下的rl_fragment_container您工具欄與android:layout_below="@+id/tb_main"並刪除填充&頁邊距。
0

更新activity_main.xml:

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
     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" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:orientation="vertical" 
     android:background="@android:color/darker_gray" 
     tools:context="los.printers.MainActivity" 
     app:theme="@style/Theme.MyTheme"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/tb_main" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:minHeight="?attr/actionBarSize" 
      android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

     <RelativeLayout 
      android:id="@+id/rl_fragment_container" 
      android:layout_below="@+id/tb_main" 

      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

    </RelativeLayout>