xml

2013-01-05 14 views
7

में ऊंचाई को हार्डकोड किए बिना बटन के ऊपर टेक्स्टव्यू प्रदर्शित करें, मैं एक टेक्स्टव्यू प्रदर्शित कर रहा हूं (मैं इसे नीचे दिए गए बटन को छोड़कर पूरी स्क्रीन भरने का इरादा रखता हूं) और एक गतिविधि में एक बटन (नीचे एक छोटा सा)। मैं चाहता हूं कि टेक्स्टव्यू बटन को ऊपर रखा जाए। मैं किसी ऊंचाई/चौड़ाई को हार्डकोड नहीं करना चाहता हूं।xml

इसलिए बटन के लिए मैंने ऊंचाई विज्ञापन चौड़ाई को word_wrap के रूप में रखा है टेक्स्टव्यू के लिए मैंने चौड़ाई को पैरेंट के रूप में रखा है।

जो मैं जानना चाहता हूं वह यह है कि, वैसे भी वैसे भी मैं टेक्स्टहाइट ऊंचाई को स्क्रीनहाइट-बटन ऊंचाई के रूप में निर्दिष्ट कर सकता हूं। मैं इसे xml फ़ाइल में करना चाहता हूं लेकिन मेरे कोड के अंदर सजावटी नहीं।

+0

अपने कोड यहाँ –

उत्तर

5

काम इस आप कुछ इस तरह बनाने के लिए प्राप्त करने के लिए करना चाहिए:

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

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/button1" 
     android:text="TextView" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:text="Button" /> 

</RelativeLayout> 

और आप एक TextView जो अपने बटन के ऊपर रहना होगा है और पूरी स्क्रीन फिट होगा।

+0

बहुत बहुत शुक्रिया डाल दिया। मेरे पास नीचे दो बटन (wrap_text दोनों) थे, इसलिए आपके सुझाव ने मुझे प्राप्त हुए दो अन्य उत्तरों की तुलना में सबसे अच्छा काम किया। अन्य दो ने मुझे लगता है कि थोड़ा tweaking के साथ भी काम किया होगा। – user1938357

+0

कोई विचार है कि अब मुझे क्रिएट विधि में टेक्स्टव्यू की ऊंचाई कैसे प्राप्त हो सकती है? textview.getHeight() काम नहीं करता है क्योंकि संसाधन पहले से तैयार नहीं हैं क्रिएट निष्पादन जिसे गतिविधि की सामग्री सेट करने के लिए उपयोग किया जाता है। – user1938357

+0

यह आपको सही जवाब दे सकता है मुझे लगता है: http://stackoverflow.com/questions/4142090/how-do-you-to-retrieve-dimensions-of-a-view-getheight-and-getwidth-always-r/4406090 # 4406090 – hardartcore

0

उपयोग RelativeLayout, fill_parent के रूप में स्थापित TextView के आयामों, तो यह नीचे दिए गए बटन जगह, सेट बटन के एंड्रॉयड: layout_below = "@ + id/TextView" और wrap_content के रूप में बटन के आयाम।

चेक दृश्य डिजाइनर में या डिवाइस में परिणाम है, यह

0

आप layout_weight विशेषता का उपयोग कर सकते हैं

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

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1" 
     android:text="TextView" /> 

    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Button" /> 

</LinearLayout> 

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