2010-08-24 18 views
7

चित्र: http://img838.imageshack.us/img838/1402/picse.pngरिलेवेटिवआउट का उपयोग करके मैं निम्नलिखित परिणाम कैसे प्राप्त करूं?

मैं Pic में लेआउट कैसे बना सकता हूं। 2 केवल रिलेवेटिवआउट का उपयोग कर। नीचे पहले स्क्रीनशॉट का एक्सएमएल लेआउट है।

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
<TextView 
    android:id="@+id/timer_textview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:layout_marginTop="10dip" 
    android:textSize="30sp" 
    android:layout_alignParentTop="true" 
    android:text="@string/timer_start" /> 

<ListView 
    android:id="@+id/questions_listview" 
    android:layout_below="@id/timer_textview" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" /> 

<Button android:id="@+id/true_btn" 
    android:text="@string/true_option" 
    android:layout_alignParentBottom="true" 
    android:layout_weight="1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<Button 
    android:id="@+id/false_btn" 
    android:text="@string/false_option" 
    android:layout_toRightOf="@id/true_btn" 
    android:layout_alignBaseline="@id/true_btn" 
    android:layout_weight="1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
</RelativeLayout> 
+2

'एंड्रॉइड: लेआउट_वेट' का कोई 'रिलेवेटिवआउट' में कोई अर्थ नहीं है। मुझे खेद है कि आप एक 'रिलेवेटिव लयआउट' का उपयोग करके जो चाहते हैं उसे लागू करने के तरीके से अवगत नहीं हैं। – CommonsWare

उत्तर

18

आप LinearLayout तल पर इस्तेमाल कर सकते हैं इस लक्ष्य को हासिल करने के लिए इसे का आधा या तो एक निश्चित मूल्य का उपयोग करें या स्क्रीन की चौड़ाई हो और बनाने minWidth -

पहले true_btn की चौड़ाई बढ़ाने के लिए आप minWidth विशेषता सेट कर सकते हैं ।

<RelativeLayout android:layout_width="fill_parent" ... > 

...  

<View android:id="@+id/helper" 
android:layout_width="0dp" 
android:layout_height="0dp" 
android:layout_alignParentBottom="true" 
android:layout_centerHorizontal="true" /> 

<Button android:id="@+id/true_btn" 
android:layout_alignParentBottom="true" 
android:layout_alignParentLeft="true" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_toLeftOf="@id/helper"/> 

<Button 
android:id="@+id/false_btn" 
android:layout_alignBaseline="@id/true_btn" 
android:layout_alignParentRight="true" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_toRightOf="@id/helper" /> 

</RelativeLayout> 

तुम सच में नेस्टेड लेआउट का उपयोग नहीं किया जा सकता: लेकिन आप RelativeLayout लेआउट केवल इतना उपयोग करना चाहते हैं?

+0

मुझे पता है कि मैं एक नेस्टेड लेआउट का उपयोग कर सकता हूं, दूसरे स्क्रीनशॉट में मैंने बिल्कुल ऐसा किया था। लेकिन मैं सिर्फ सापेक्ष लयआउट की सीमाओं को जानना चाहता हूं। –

+0

क्या आपने मेरा कोड आजमाया? – plugmind

+0

ओह ... दोस्त काम नहीं किया। वैसे भी धन्यवाद @ radek-k –

0

आप

<Button android:id="@+id/true_btn" 
    android:text="@string/true_option" 
    android:layout_alignParentBottom="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<Button 
    android:id="@+id/false_btn" 
    android:text="@string/false_option" 
    android:layout_toRightOf="@id/true_btn" 
    android:layout_alignBaseline="@id/true_btn" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

हालांकि false_btn सभी शेष अंतरिक्ष हो जाता है आप कम से कम पूरी चौड़ाई का उपयोग करने के लिए बटन को बदलते हैं।

+0

मुझे आज़माएं और मैं इस पर वापस आऊंगा। –

+0

आपका विचार अच्छा है, मैं बस जानना चाहता हूं कि सामान्य रूप से स्क्रीन की चौड़ाई निर्दिष्ट करने के तरीके हैं? (यानी) विभिन्न स्क्रीन आकारों के साथ सभी उपकरणों पर काम करना चाहिए। –

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

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