2010-12-29 10 views
17

के अंदर लेआउट प्रबंधित करें मैं अपनी मुख्य गतिविधि के रूप में TableRows के साथ एक TableLayout का उपयोग कर रहा हूँ।एक क्षैतिज ओरिएंटेड रेडियोग्रुप

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

तो
होने की बजाय। (एक्स) (एक्स) अंतराल |
मेरे पास
| (x) अंतराल (x) |

जहां (x) रेडियो बटन हैं और | स्क्रीन के किनारों

मैं मध्य में दोनों बटन (यानी | अंतराल (x) (x) अंतराल) को रखने के लिए गुरुत्वाकर्षण (center_horizontal) का उपयोग कर सकता हूं। हालांकि मैं उन्हें विभाजित करने में सक्षम नहीं लग सकता जिस तरह से मैं

उत्तर

0

से पहले जैसा कहना चाहता हूं, क्या आपको कभी इसका समाधान मिला? मेरा इंटरमीडिएट समाधान मदद कर सकता है, लेकिन यह मेरे लिए पूरी तस्वीर नहीं है। मैं विशिष्ट चौड़ाई सेट करके ऐसा करने में सक्षम किया गया है, लेकिन इस दृश्य स्क्रीन की चौड़ाई फिट करने के लिए आकार बदलने के लिए अनुमति नहीं देता:

<RelativeLayout 
    android:id="@+id/overall_layout" 
    android:layout_width="290dp" android:layout_height="wrap_content"> 

    <RadioGroup android:id="@+id/overall" 
     android:layout_width="fill_parent" android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <RadioButton android:id="@+id/overall_1" android:tag="1" 
      android:button="@drawable/radio_1" 
      android:layout_width="50dp" 
      android:layout_marginRight="10dp" 
      android:layout_height="wrap_content"></RadioButton> 
     <RadioButton android:id="@+id/overall_2" android:tag="2" 
      android:button="@drawable/radio_2" 
      android:layout_width="50dp" 
      android:layout_marginRight="10dp" 
      android:layout_height="wrap_content"></RadioButton> 
     <RadioButton android:id="@+id/overall_3" android:tag="3" 
      android:button="@drawable/radio_3" 
      android:layout_width="50dp" 
      android:layout_marginRight="10dp" 
      android:layout_height="wrap_content"></RadioButton> 
     <RadioButton android:id="@+id/overall_4" android:tag="4" 
      android:button="@drawable/radio_4" 
      android:layout_width="50dp" 
      android:layout_marginRight="10dp" 
      android:layout_height="wrap_content"></RadioButton> 
     <RadioButton android:id="@+id/overall_5" android:tag="5" 
      android:button="@drawable/radio_5" 
      android:layout_width="50dp" 
      android:layout_height="wrap_content"></RadioButton> 
    </RadioGroup> 
    <TextView android:text="left" android:id="@+id/left" 
     android:layout_below="@id/overall" 
     android:layout_alignParentLeft="true" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> 
    <TextView android:text="right" android:id="@+id/right" 
     android:layout_below="@id/overall" 
     android:layout_alignParentRight="true" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> 
    </RelativeLayout> 

नोट वहाँ पिछले बटन पर कोई मार्जिन है।

मैं एक रेडियो समूह में 5 कस्टम बटन रखने की कोशिश कर रहा हूं, जिसमें पहला बाएं-न्यायसंगत और अंतिम अधिकार-उचित है। बटन बिल्कुल 50 पिक्सल चौड़े हैं और मैं अलग-अलग बटन से जुड़े किसी भी पाठ को नहीं चाहता हूं। नीचे दिए गए 2 ग्रंथ बाएं और दाएं-सापेक्ष लेआउट में सही हैं। "Layout_gravity" का कोई प्रभाव नहीं पड़ता है और "लेआउट_वेट" प्रत्येक बटन के दाईं ओर पैडिंग जोड़ता है, जो सही-बटन को उचित नहीं ठहराता है।

इस पर बहुत सारे बाल खींच रहे हैं।

9

मेरा समाधान मिला। वजन और गुरुत्वाकर्षण का संयोजन और मार्जिन को हटा देना। रेडियो समूह में layout_width = "fill_parent" हो सकता है। प्रत्येक रेडियो बटन में layout_weight = "1" होना चाहिए, लेकिन प्रत्येक radiobutton के लिए layout_width अभी भी "37" के डिफ़ॉल्ट को ओवरराइड करने के लिए निर्दिष्ट किया जाना चाहिए जो मुझे लगता है कि डिफ़ॉल्ट रेडियो बटन छवि चौड़ाई है।

 <RadioGroup android:id="@+id/overall" 
     android:layout_width="fill_parent" android:layout_height="80dp" 
     android:gravity="center" 
     android:orientation="horizontal"> 

पहले बटन होना चाहिए:

   android:layout_weight="1" 
      android:layout_gravity="center|left" 

अंतिम बटन होना चाहिए:

  android:layout_gravity="center|right" 

नोट: सभी बटन layout_gravioty सेट है, लेकिन कोई layout_weight सही सबसे बटन के लिए सेटिंग!

+0

मैं प्रयोग किया जाता है कि, लेकिन यह मेरी कोड लिए काम does not, पहला बटन पूरी लाइन – elfekz

32

आप सभी को समान रूप से अंतरिक्ष बटन के एक मनमाना संख्या क्षैतिज स्क्रीन भर में की जरूरत है:

  1. RadioGroup है android:orientation="horizontal" & android:layout_width="fill_parent"
  2. प्रत्येक रेडियो बटन है android:layout_weight="1" है, को छोड़कर के लिए दाएं बटन ( को स्क्रीन के दाएं किनारे पर लाइन बनाने के लिए)!

Landscape screenshot

यह मैं घंटे लगे यह पता लगाने की।

एक सर्वेक्षण ऐप के लिए, दो टेक्स्ट लेबल्स के बोनस और स्क्रीन के दाएं और बाएं किनारों के साथ यहां कुछ उदाहरण कोड दिया गया है।

<RadioGroup 
    android:id="@+id/radio_group" 
    android:orientation="horizontal" 
    android:layout_below="@id/question" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:visibility="gone" 
> 
    <RadioButton 
     android:id="@+id/strong_disagree_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="1" 
    /> 
    <RadioButton 
     android:id="@+id/disagree_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@string/disagree" 
    /> 
    <RadioButton 
     android:id="@+id/neutral_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@string/neutral" 
    /> 
    <RadioButton 
     android:id="@+id/agree_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@string/agree" 
    /> 
    <RadioButton 
     android:id="@+id/strong_agree_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="5" 
    /> 
</RadioGroup> 
<TextView 
    android:id="@+id/disagree_label" 
    android:text="@string/strongly_disagree_txt" 
    android:layout_below="@id/radio_group" 
    style="@style/TextAppearance" 
    android:visibility="gone" 
    /> 
<TextView 
    android:id="@+id/agree_label" 
    android:text="@string/strongly_agree_txt" 
    android:layout_below="@id/radio_group" 
    android:layout_alignParentRight="true" 
    style="@style/TextAppearance" 
    android:layout_width="wrap_content" 
    android:visibility="gone" 
    /> 
+1

मैं इस कोशिश की को शामिल किया गया और यह आपके द्वारा संलग्न स्क्रीनशॉट के साथ समान नहीं है। – KarenAnne

+1

इसके लिए धन्यवाद .. :) – KarenAnne

+1

इसके लिए बहुत बहुत धन्यवाद, मैं अपने बालों को खींच रहा हूं! – Garbit

0

तो मैं तुम सही सवाल को समझते हैं, आप भी अगले कोड RadioGroup अंदर की कोशिश कर सकते हैं:

<ToggleButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<View 
    android:id="@+id/view1" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" /> 

<ToggleButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
संबंधित मुद्दे