2011-09-04 13 views
9

के साथ कठिनाई मैं एक एंड्रॉइड लेआउट बनाने की कोशिश कर रहा हूं: एक लंबवत रैखिकलायआउट के अंदर 3 घटक। केंद्र घटक ScrollView है जिसमें TextView है। जब TextView में टेक्स्ट की एक बड़ी मात्रा (स्क्रीन पर फिट करने से अधिक) शामिल है, तो ScrollView स्क्रीन के निचले हिस्से तक सभी तरह से बढ़ता है, स्क्रॉलबार दिखाता है, और के साथ Button के साथ अंतिम घटक को धक्का देता है, स्क्रीन।

के अंदर TextView के अंदर पाठ पर्याप्त छोटा है, स्क्रीन के निचले हिस्से में बटन पूरी तरह से स्थित है।

लेआउट मैं प्राप्त करने के लिए कोशिश कर रहा हूँ है:स्क्रॉलव्यू और लाइनरलायआउट

लेआउट मैं लिखा है के लिए XML है:

<?xml version="1.0" encoding="UTF-8"?> 

<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="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="#FFFFFF" 
      android:layout_marginLeft="10dip" 
      android:layout_marginRight="10dip" 
      android:layout_marginTop="10dip" 
      android:layout_marginBottom="10dip" 
      android:text="Title /> 

    <ScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

     <TextView android:id="@+id/text" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:autoLink="web" 
       android:textColor="#FFFFFF" 
       android:background="#444444" 
       android:padding="10dip" /> 

    </ScrollView> 

    <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1"> 

     <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 

     <Button android:id="@+id/login_button" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom" 
       android:layout_weight="1" 
       android:text="@string/next_button"/> 

    </LinearLayout> 

</LinearLayout> 

उत्तर

6

scrollview दूसरे दृश्य वस्तु है और wrap_content पर सेट है, जो स्क्रीन से अधिक है।

मैं एक सापेक्ष लयआउट की अनुशंसा करता हूं। android:alignParentTop="true" के साथ पहले शीर्ष टेक्स्टव्यू, android:alignParentBottom="true" के साथ नीचे रैखिकलायआउट और android:alignBelow="@id/whatYouCallTheHeader मान के साथ xml में अंतिम रूप से सूचीबद्ध स्क्रॉलव्यू।

यह स्क्रीन के निचले हिस्से में निचला पट्टी को संरेखित करेगा, और शीर्ष पर शीर्षलेख, आकार चाहे कोई फर्क नहीं पड़ता। हेडर और पाद लेख के बाद, स्क्रॉलव्यू का अपना स्थान होगा।

+0

आप 1.6 लक्ष्य यह केवल एक एक्सएमएल के माध्यम से पारित करता है के रूप में के लिए लिख रहे हैं, इसलिए किसी भी संदर्भ से बाहर रखा जा करने के लिए इससे पहले कि यह संदर्भित है है है। 2.1+ दो पास बनाता है। – Phobos

2

आपको LinearLayout के बजाय सापेक्ष Layout के लिए जाना चाहिए। और आप कुछ गुणों का उपयोग कर सकते हैं जैसे alignBelow और सब।

2

ScrollView यानी लेआउट वजन जोड़ने का प्रयास करें।

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"> 

यह एक ऐसी स्थिति एक आप प्रस्तुत कर रहे हैं करने के लिए लगभग समान में मेरे लिए काम किया लेकिन मुझे, सोच क्यों, क्योंकि यह जवाबी सहज है छोड़ दिया है कि 0 से नियंत्रण के लेआउट वजन बढ़ाने (डिफ़ॉल्ट अगर आप layout_weight निर्दिष्ट नहीं करें) 1 को एक नियंत्रण करना चाहिए जो पहले से ही बहुत अधिक जगह का उपयोग कर रहा है।

मुझे संदेह है कि यह काम करने का कारण यह है कि लेआउट_वेट निर्दिष्ट नहीं करने से आप वास्तव में लेआउट को अन्य नियंत्रणों के सापेक्ष स्क्रॉल व्यू के आकार को अनदेखा करने की अनुमति देते हैं और इसके विपरीत यदि कोई निर्दिष्ट करता है तो आप इसे अनुपात में कम करने की अनुमति देते हैं वजन जो आप असाइन करते हैं।

2

! [फिक्स्ड हैडर-पाद और स्क्रॉल करने योग्य शारीरिक लेआउट] [1]


यह आप के लिए क्या देख रहे है। एंड्रॉइड में अधिकांश ऐप में इस प्रकार का लेआउट था, एक निश्चित हेडर और पाद लेख और स्क्रोल करने योग्य निकाय। इस लेआउट के लिए एक्सएमएल


<?xml version="1.0" encoding="UTF-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
     android:background="#5599DD" 
     android:layout_height="fill_parent"> 
     <!-- Header goes here --> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="#FFFFFF" 
      android:layout_marginLeft="10dip" 
      android:layout_marginRight="10dip" 
      android:layout_marginTop="10dip" 
      android:layout_marginBottom="10dip" 
      android:textSize="20sp" 
      android:layout_gravity="center" 
      android:text="Title" /> 
     <!-- Body goes here --> 
     <ScrollView 
      android:layout_weight="1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:id="@+id/text" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:autoLink="web" 
       android:text="@string/lorem_ipsum" 
       android:textColor="#FFFFFF" 

       android:padding="10dip" /> 
     </ScrollView> 
     <!-- footer goes here --> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
       <Button 
        android:id="@+id/login_button" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:layout_gravity="bottom" 
        android:layout_alignParentRight="true" 
        android:text="Button"/> 

      </RelativeLayout> 
    </LinearLayout> 
</LinearLayout> 
संबंधित मुद्दे