2013-02-15 27 views
10

मैं 3 बटन जहाँ वे एक दूसरे के नीचे दिखाई देते हैं नीचे layout.xml है ...रैखिक लेआउट - एंड्रॉयड

   <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" 
       android:padding="10dip" > 

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

        <Button 
         android:id="@+id/btn_1" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="Car" /> 

        <Button 
         android:id="@+id/btn_2" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="Vehicle" /> 
       </LinearLayout> 

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

        <Button 
         android:id="@+id/btn_3" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Bike" /> 
       </LinearLayout> 
      </LinearLayout> 

मैं द्वारा पहले दो बटन पक्ष करना चाहते हैं पक्ष (बीटीएन_1 और बीटीएन_2)। क्या कोई मुझे यह कैसे करने के बारे में संकेत दे सकता है ???

धन्यवाद एक बहुत

+0

है वही मामला: http://stackoverflow.com/questions/5551349/2-buttons-side-by-side-android-layouts/21411490#21411490 – iarroyo

उत्तर

16

सिर्फ अपने लेआउट के android:orientation="horizontal" और हर चीज ठीक

3

बदलें Horizontal.And में रैखिक लेआउट उन्मुखीकरण कार्यक्षेत्र तो 1 या 2 के रूप में अपने दोनों बटन के लिए वजन दें करने के लिए काम करेंगे android:orientation="vertical" बदल आपकी इच्छा के अनुसार। बटनों को समान रूप से व्यवस्थित किया जाएगा।

7
यह करने के लिए

सबसे अच्छा तरीका लेआउट बनाने के लिए है और फिर इस कोड

<TableRow 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

<Button 
    android:id="@+id/Button9" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="left" 
    android:text="@string/Home1"/> 

<Button 
    android:id="@+id/Button11" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="right"  
    android:text="@string/NextL"/> 

इस आकार में की तरह अपने बटन लगाना आप एक ही पंक्ति में इतना आसान दो बटन है: डी

+0

ऐसा लगता है कि आप एक बंद टैग भूल गए हैं? साथ ही, [डॉक्स] (http://developer.android.com/reference/android/widget/TableRow.html) के अनुसार, "एक टेबलरो हमेशा टेबललेआउट के बच्चे के रूप में उपयोग किया जाना चाहिए"। – dst

+0

हाँ, मैं उनको भूल गया, और कोई भी दायित्व नहीं है जिसका उपयोग अधिकांश लेआउट के अंदर किया जा सकता है, मैंने उन्हें लाइनरलायआउट के अंदर उपयोग किया और यह – user3287335

+0

पर काम करता है, यही कारण है कि दस्तावेज़ केवल * चाहिए * और * * * का उल्लेख नहीं करना चाहिए। लेकिन जैसे ही दस्तावेज़ इसके खिलाफ अनुशंसा करते हैं, मैं नए एंड्रॉइड संस्करणों को तोड़ने के मामले में इसकी सिफारिश नहीं करता हूं। – dst