2012-01-02 20 views
5

मैं एक इंटरफ़ेस बनाने की कोशिश कर रहा हूं, जहां उपयोगकर्ता को दो या दो से अधिक बटन प्रदर्शित किए जाएंगे, यदि कोई बटन क्लिक किया गया है, तो कुछ लेआउट उन्हें प्रदर्शित किए जाएंगे। मैं इस प्रयोजन के लिए स्लाइडिंग ड्रावर का उपयोग कर रहा हूं।एंड्रॉइड लेआउट_विड्थ और लेआउट_हेइट, यह कैसे काम करता है?

ठीक है, मैं लेआउट_विड्थ & लेआउट_हेइट गुण से उलझन में हूं।

यदि मैं नीचे दिए गए गुणों को सेट करता हूं तो स्क्रीन पर "हैंडल 1" दिखाया जाता है।

android:layout_width="fill_parent" android:layout_height="wrap_content" 

ईमानदारी से कह रहा है, मेरे पास इन दोनों गुणों के बारे में पर्याप्त जानकारी नहीं है। क्या कोई उनके बारे में अपना ज्ञान साझा कर सकता है?

main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <SlidingDrawer android:id="@+id/slidingDrawer1" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:handle="@+id/handle1" 
      android:content="@+id/content1"> 
       <Button android:text="Handle 1" android:layout_height="wrap_content" 
         android:layout_width="fill_parent" android:id="@+id/handle1"></Button> 
       <LinearLayout android:id="@+id/content1" 
         android:layout_width="fill_parent" android:layout_height="wrap_content" 
         android:orientation="vertical" android:gravity="center" 
         android:background="#FF444444"> 
         <Button android:text="Handle 1 Item 1" android:layout_height="wrap_content" 
           android:layout_width="wrap_content" android:id="@+id/item1"></Button> 
       </LinearLayout> 
    </SlidingDrawer> 

    <SlidingDrawer android:id="@+id/slidingDrawer2" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:handle="@+id/handle2" 
      android:content="@+id/content2"> 
       <Button android:text="Handle 2" android:layout_height="wrap_content" 
         android:layout_width="fill_parent" android:id="@+id/handle2"></Button> 
       <LinearLayout android:id="@+id/content2" 
         android:layout_width="fill_parent" android:layout_height="wrap_content" 
         android:orientation="vertical" android:gravity="center" 
         android:background="#FF444444"> 
         <Button android:text="Handle 2 Item 1" android:layout_height="wrap_content" 
           android:layout_width="wrap_content" android:id="@+id/item2"></Button> 
       </LinearLayout> 
    </SlidingDrawer>  
</LinearLayout> 
+5

आप जांच की है [प्रलेखन] (http: // developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#FILL_PARENT)? यह बहुत स्पष्ट imho है। –

+1

अच्छा सवाल। कुछ महीने पहले जब मैंने पहली बार शुरू किया था, तो मैं इस बारे में उलझन में था। इसे कुछ दिन दें, और आप इसे लटका लेंगे। – Reid

उत्तर

5

एक दृश्य की layout_width और layout_height गुण अपनी मूल कंटेनर द्वारा इस्तेमाल किया जा करने का इरादा कर रहे हैं। कुछ कंटेनर इनमें से एक या दोनों को अनदेखा करते हैं; सबसे सम्मान उन्हें। मूल्यों का उपयोग कैसे किया जाएगा, यह समझने के लिए आपको कंटेनर के दस्तावेज़ (आपके मामले में, स्लाइडिंग ड्रावर) से परामर्श करने की आवश्यकता है।

आप पूर्ण main.xml नहीं दिखाते हैं, इसलिए यह कहना मुश्किल है कि क्या गलत हो रहा है। अगर आप गलत की छवि पोस्ट करते हैं तो यह भी मदद करेगा।

संपादित

अपना पूरा लेआउट देखने के बाद, मुझे लगता है कि मूल समस्या यहां है कि आप एक LinearLayout उपयोग कर रहे हैं SlidingDrawers को रोकने के लिए है। docs for SlidingDrawer नोट के रूप में, उन्हें या तो फ़्रेमलाउट या रिलेटिव लेआउट में होना चाहिए (वास्तव में, कोई कंटेनर जो एकाधिक विचारों को एक-दूसरे के ऊपर बैठने की अनुमति देता है)।

एक और संभावना यह है कि दूसरा स्लाइडिंग ड्रावर सीधे पहले के तहत रखा जा रहा है। दूसरे बटन के आकार को बदलने का प्रयास करें (उदाहरण के लिए, टेक्स्ट को लंबा बनाएं) और देखें कि क्या यह बटन के दोनों तरफ बाहर निकलता है।

+0

मैंने पूरा main.xml प्रदान किया है, कृपया मेरा प्रश्न देखें। –

+0

@Yaqub अहमद - मैंने अपना जवाब अपडेट किया। –

+0

ग्रेट धन्यवाद। इसे मुझे देखने दो। –

4

fill_parent = match_parent, और इसका मतलब है कि यह चौड़ाई या ऊंचाई लेता है (जो कभी भी "जनक" कंटेनर

wrap_content की संपत्ति के रूप में निर्दिष्ट किया जा रहा है) का अर्थ है कि ऊंचाई या चौड़ाई ऊंचाई या "बच्चा"

इसके बजाय आप match_parent या wrap_content का उपयोग करने का भार का उपयोग करना चाहते की चौड़ाई पर ले जाता आम तौर पर।

जब आप वजन का उपयोग करते हैं तो आप चौड़ाई को 0 डीपी पर सेट करना चाहते हैं।

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/main" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" > 

    <LinearLayout 
    android:id="@+id/lowerLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="1.0" > 
      <LinearLayout 
      android:id="@+id/headerLayout" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_weight=".7" > 
       <Button 
        android:id="@+id/previousMonthButton" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Previous" /> 

       <TextView 
        android:id="@+id/monthName" 
        android:layout_width="0dip" 
        android:layout_height="wrap_content" 
        android:text="Large Text" 
        android:layout_weight="1" 
        android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_horizontal" /> 

       <Button 
        android:id="@+id/nextMonthButton" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Next" /> 

      </LinearLayout> 

      <LinearLayout 
      android:id="@+id/lowerLayout3" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_weight=".3" > 

       <Button 
        android:id="@+id/addEvent" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 

      </LinearLayout> 

    </LinearLayout> 
    <LinearLayout 
    android:id="@+id/lowerLayout2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="1.0" > 

     <LinearLayout 
      android:id="@+id/monthView" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:layout_weight=".7" > 

     </LinearLayout> 

     <ListView 
      android:id="@+id/listView1" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight=".3" > 
     </ListView> 
    </LinearLayout> 

</LinearLayout> 
+0

मुझे यह पता है, लेकिन मेरे प्रदत्त एक्सएमएल को देखें, क्यों यह उपरोक्त नियम लागू होने पर "हैंडल 1" दिखा रहा है, इसे "हैंडल 1" और "हैंडल 2" दोनों दिखाना चाहिए। –

+0

आप माता-पिता को दो बार भर रहे हैं। लेआउट चौड़ाई को fill_parent पर सेट करने के बजाय वजन का उपयोग करने का प्रयास करें। यह भी ध्यान रखें कि fill_parent को बहिष्कृत किया गया है; इसके बजाय match_parent का उपयोग करें। मैंने अपना जवाब संपादित कर दिया है, इसलिए मैं आपको इसका एक उदाहरण दिखा सकता हूं। – Reid

0

मुझे लगता है कि आप 2 स्लाइडिंग ड्रावर जोड़ने की कोशिश कर रहे हैं।

स्लाइडिंग ड्रावर का आकार परिभाषित करता है कि एक बार स्लीड आउट होने पर सामग्री कितनी जगह पर कब्जा कर लेगी, इसलिए स्लाइडिंग ड्रावर आमतौर पर इसके आयामों के लिए match_parent का उपयोग करना चाहिए, इस मामले में एक दूसरे को ओवरलैप करता है ताकि आप हैंडलर 2 को नहीं देख सकें।

यदि आप पहली स्लाइडिंग ड्रावर की "चला गया" दृश्यता सेट करते हैं तो आप अन्य को देख सकते हैं।

अद्यतन

हाय,

इस कोड का प्रयास करें तो यह आपको मदद मिल सकती है

<?xml version="1.0" encoding="utf-8"?> 

<SlidingDrawer 
    android:id="@+id/slidingDrawer1" 
    android:layout_width="fill_parent" 
    android:layout_height="0dip" 
    android:layout_weight="1" 
    android:content="@+id/content1" 
    android:handle="@+id/handle1" > 

    <Button 
     android:id="@+id/handle1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Handle 1" > 
    </Button> 

    <LinearLayout 
     android:id="@+id/content1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#FF444444" 
     android:gravity="center" 
     android:orientation="vertical" > 

     <Button 
      android:id="@+id/item1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Handle 1 Item 1" > 
     </Button> 
    </LinearLayout> 
</SlidingDrawer> 
+0

हाँ मैं अपने प्रश्न से स्पष्ट रूप से एक से अधिक स्लाइडिंग ड्रॉवर जोड़ना चाहता हूं। अगर मैं दृश्यता को सेट करने के लिए सेट करता हूं तो पहला स्लाइडिंग ड्रॉवर अदृश्य हो जाएगा। –

+0

@YaqubAhmad अद्यतन पोस्ट की जांच करें ... – loks