2016-02-13 17 views
5

हाय मैं छोटे एंड्रॉइड एप्लिकेशन को विकसित कर रहा हूं जिसमें मैं 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

मैं वास्तव में इस समाधान के साथ खुश नहीं हूँ, लेकिन मैं अब तक इस पाया:

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

यह समस्या भी मेरे लिए आया था, तो: अपने RelativeLayout जो नीचे AppBarLayout है android:elevation="5dp" जोड़ने की कोशिश मैं इसके बारे में कुछ और जांच करने की कोशिश करूंगा। (मेरे लिए जादू मूल्य मत पूछो क्यों, 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

ऊंचाई चाल :) करता है –

संबंधित मुद्दे