2016-02-13 21 views
5

Merhaba Ben AppBarLayout ile araç çubuğu görüntülemeye çalıştığım küçük android uygulama geliştiriyorum. Araç çubuğumun üstünde bazı görünümler göstermek istiyorum. Aşağıdaki şekilde bu çalıştı: Android eklendi AppBarLayout her zaman üstte geliyor

<?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> 

Yani yukarıdaki düzende daha sonra hem nispi düzenleri benim AppBarLayout altına giriyor

. Ama onları toolbar_view'umun üstünde göstermek istiyorum. Bir şey eksik ya da yanlış bir şey yapıyorum. Yardıma ihtiyacım var. Teşekkür ederim.

cevap

2

Gerçekten bu çözüm ile mutlu değilim, ama şimdiye kadar bu bulundu:

Bu sorun aynı zamanda benim için geldi
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="150dp" 
    android:elevation="5dp" 
    android:background="@android:color/holo_red_dark" /> 

, böylece: AppBarLayout altındadır senin RelativeLayout için android:elevation="5dp" eklemeyi deneyin Biraz daha araştırmaya çalışacağım. (Benim için sihirli değeri neden diye sorma, 5DP budur.)

Alternatif AppBarLayout içine görüşlerinizi koyabilirsiniz:

<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

yükseklik hile :) yapar –

İlgili konular