2009-07-24 4 views
69

मैं एक वीडियो शीर्षक और टैग प्रदर्शित करने के लिए एक संवाद बनाना चाहता हूं। पाठ के नीचे मैं बटन जोड़ना, संपादित करना और हटाना चाहता हूं और इन तत्वों को एक ही आकार में बनाना चाहता हूं। क्या किसी को भी LinearView के अंदर तत्व बनाने के लिए .xml लेआउट फ़ाइल को संशोधित करने का तरीका पता है?एंड्रॉइड: सभी तत्वों को LinearLayout के अंदर समान आकार कैसे बनाएं?

वर्तमान लेआउट फ़ाइल इस तरह दिखता है:

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

    <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/txtTitle" android:text="[Title]" > 
      </TextView> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/txtTags"    
       android:text="[Tags]" > 
      </TextView> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/btnPlay" 
      android:text="View"> 
     </Button> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/btnEdit" 
      android:text="Edit"> 
     </Button> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/btnDelete" 
      android:text="Delete"> 
     </Button> 

    </LinearLayout> 

</LinearLayout> 

मैं अगर किसी को भी चिपकाया फ़ाइल सामग्री को संशोधित करके समाधान दिखा सकता है की सराहना करेंगे।

धन्यवाद!

उत्तर

148

और android:layout_weight="1" का उपयोग तीन Button एस पर करें। यह कहता है कि बटनों को 0 पिक्सल से अधिक नहीं लेना चाहिए, लेकिन उनमें से तीन को उनके बीच कोई अतिरिक्त जगह विभाजित करनी चाहिए। इससे आपको इच्छित दृश्य प्रभाव मिलना चाहिए।

+4

यदि आप _REALLY_ चाहते थे कि आप वैकल्पिक रूप से एंड्रॉइड के साथ टेबललेआउट का उपयोग कर सकें: stretchColumns = "0,1,2"। –

+0

बहुत बढ़िया ... तो इसका मतलब है, अगर हम 0px के रूप में चौड़ाई डालते हैं, तो वजन सेटिंग्स को ओवरराइड कर देगा? ऐसा क्यों है? – noob

+0

यह सिर्फ सही काम किया। – Proverbio

28

एक और तरीका android:layout_width="fill_parent" और android:layout_weight="1" बनाना है यह ठीक काम करेगा !!!

+13

आप इस उत्तर के बारे में वास्तव में उत्साहित थे। :-) उत्साह से प्यार करो! –

+0

कॉमन्सवेयर का समाधान मेरे लिए काम नहीं करता था, लेकिन ऐसा हुआ! :) मैंने "match_parent" का उपयोग किया क्योंकि मैंने सुना है कि आपको इसे "fill_parent" से अधिक पसंद करना चाहिए, लेकिन दोनों काम करते हैं। – codepleb

1

मैंने एक समान स्पेसलाइट लिखा जो मुझे लगता है कि आपकी समस्या का समाधान होगा। यह LinearLayout के समान है, लेकिन यह बच्चे के विचारों के आकार को विकृत नहीं करता है। इसे देखें: http://www.dev-smart.com/archives/225

16

LinearLayout का उपयोग अपने वांछित weightSum के साथ करें और layout_weight के साथ तत्व बनाएं। यहाँ एक उदाहरण है ...

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="5"> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_share_white_36dp"/> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_search_white_36dp"/> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_event_note_white_36dp"/> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_brush_white_36dp"/> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_menu_white_36dp"/> 
</LinearLayout> 

तो, सभी तत्वों का वजन राशि 5. यहाँ स्क्रीनशॉट है ...

enter image description here

ध्यान दें कि, Google Material Design माउस उपयोग किया जाता है। उम्मीद है कि यह सहायक है।

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