2016-02-13 14 views
5

Witam Zajmuję się tworzeniem małej aplikacji na Androida, w której próbuję wyświetlić pasek narzędzi z AppBarLayout. Chcę wyświetlić jakiś widok na moim pasku narzędzi. Próbowałem to w następujący sposób:Android widget AppBarLayout zawsze jest na topie

<?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" 
    tools:context="com.example.nileshkashid.samplesearchbarapplication.Main2Activity"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/toolbar_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     > 
     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@android:color/transparent" 
      /> 

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

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="150dp" 
     android:background="@android:color/holo_red_dark" 
     ></RelativeLayout> 

    <RelativeLayout 
     android:layout_width="150dp" 
     android:layout_height="150dp" 
     android:background="@android:color/holo_green_dark" 
     ></RelativeLayout> 


</RelativeLayout> 

Tak więc w powyższym układzie później oba względne układy przychodzi pod moim AppBarLayout. Ale chcę pokazać je na moim toolbar_view. Czy brakuje mi czegoś lub robię coś nie tak. Potrzebuję pomocy. Dziękuję Ci.

Odpowiedz

2

nie jestem naprawdę zadowolony z tego rozwiązania, ale okazało się to do tej pory: spróbować dodać android:elevation="5dp" do swojej RelativeLayout czyli poniżej AppBarLayout:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="150dp" 
    android:elevation="5dp" 
    android:background="@android:color/holo_red_dark" /> 

Problem ten pojawił się również dla mnie, więc Spróbuję zbadać więcej na ten temat. (Dla mnie wartość magia jest 5DP, nie pytajcie dlaczego).

Alternatywnie można umieścić swoje poglądy wewnątrz AppBarLayout:

<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" tools:context="com.example.nileshkashid.samplesearchbarapplication.Main2Activity"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/toolbar_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <!-- You have to use a RelativeLayout here, because AppBarLayout is a LinearLayout. --> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="@android:color/transparent" /> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="150dp" 
       android:background="@android:color/holo_red_dark" /> 

     </RelativeLayout> 

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

    .... 

</RelativeLayout> 
+0

elewacja robi trick :) –

Powiązane problemy