2016-02-13 5 views
5

こんにちは私はAppBarLayoutでツールバーを表示しようとしている小さなアンドロイドアプリケーションを開発しています。私は私のツールバーの上にいくつかのビューを表示したい。私は、次の方法でこれを試してみました: AndroidウィジェットAppBarLayoutは常に上に来る

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

は、したがって、上記のレイアウトでは、後に、両方の相対的なレイアウトは私のAppBarLayout下に来る

。しかし私はそれらを私の toolbar_viewの上に示したいと思います。私は何かを欠いているか、何か間違っている。助けが要る。ありがとうございました。

答えて

2

私は本当にこの解決策に満足していないが、私は今のところこれを見つけた: AppBarLayoutを下回っているあなたのRelativeLayoutandroid:elevation="5dp"を追加しよう:

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

また、この問題は、そう、私のために来ました私はそれについてもう少し詳しく調べようとします。 (理由は聞かないで、私にとっては魔法の値は5DPである。)

代わりにあなたが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

標高はトリックを行います:) –

関連する問題