2011-08-04 12 views
6

में प्रदर्शित नहीं होने वाला बटन TextView के बाद में Button जोड़ने की कोशिश कर रहा हूं लेकिन यह प्रदर्शित नहीं हो रहा है।लाइनरलायआउट

यहाँ मेरी लेआउट कोड

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="45dip"> 

    <TextView android:layout_width="fill_parent" 
     android:layout_height="45dip" 
     android:paddingLeft="5dip" 
     android:paddingRight="5dip" 
     android:textStyle="bold" 
     android:textSize="17dip" 
     android:gravity="center_vertical" 
     android:id="@+id/tvChild" 
     android:text="Children" 
     android:textColor="#ffCCCC22" /> 

    <Button android:id="@+id/submit" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:text="Submit" /> 
</LinearLayout> 

TextView है उचित पाठ के साथ सही ढंग से प्रदर्शित किया जाता है, लेकिन एक Button बजाय मैं तीन से चार लाइनों की लंबाई का एक बड़ा रिक्त स्थान हो रही है।

मुझे क्या याद आ रही है?

+3

एंड्रॉयड बदलें के बजाय: layout_width = "fill_parent" की TextView Android के लिए: layout_width = "wrap_content" या अपने LinearLayout टैग में एंड्रॉयड जोड़ें: अभिविन्यास = "लंबवत" –

+0

धन्यवाद कार्तिक .. यह – Codemator

उत्तर

6

इसे आजमाएं।

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout android:id="@+id/LinearLayout01" 
     android:layout_width="fill_parent" android:layout_height="45dip" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 
     <TextView android:layout_width="wrap_content" 
      android:layout_height="45dip" android:paddingLeft="5dip" 
      android:paddingRight="5dip" android:textStyle="bold" android:textSize="17dip" 
      android:gravity="center_vertical" android:id="@+id/tvChild" 
      android:text="Children" android:textColor="#ffCCCC22" 
      /> 
      <Button android:id="@+id/submit" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:text="Submit" /> 
    </LinearLayout> 

उपयोग android:layout_width="wrap_content" android:layout_width="fill_parent"TextView के लिए और Button

+0

बिल्कुल सही .. इससे मुझे बहुत मदद मिली .. – Codemator

+0

भले ही ओपी नया है, आपको * अपवोट * और * उत्तर स्वीकृति के लिए नहीं पूछना चाहिए। – Reno

+1

मैंने जो लिखा है उसे पढ़ें: यहां तक ​​कि यदि वह नया है तो आपको यह नहीं करना चाहिए। आप उसे बता सकते हैं * उत्तर कैसे स्वीकार करें *। उपयोगकर्ता को * अपना * उत्तर स्वीकार करने या यहां तक ​​कि इसे ऊपर उठाने के लिए बाध्य न करें। आपका उत्तर * व्याख्या नहीं करता है * आपका समाधान क्यों काम करता है। [इसे पढ़ें] (http://meta.stackexchange.com/questions/95470/down-vote-code-only-answers) – Reno

4

समस्या यह थी कि आप TextView के लिए android:layout_width="fill_parent" सेट कर रहे थे, इसलिए TextView प्रदर्शित करने के लिए यह पूरी स्क्रीन चौड़ाई ले गया। और यह Button प्रदर्शित करने में सक्षम नहीं था।

  1. एक ही पंक्ति पर TextView और Button जोड़ना:

    यहाँ दो आप के लिए विकल्प हैं।

    TextViewwrap_content की विशेषता बदलें।

  2. TextView और Button लंबवत जोड़ना।

    LinearLayout की ओरिएंटेशन विशेषता vertical पर बदलें।

+0

काम करता है बिल्कुल .. मुझे मिल गया .. आपके मूल्यवान समय के लिए धन्यवाद – Codemator

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