LinearLayout एक स्क्रॉल दृश्य के अंदर विस्तार नहीं कर रहा है


371

मेरे पास एक LinearLayoutअंदर है ScrollViewजो है android:layout_height="fill_parent", लेकिन यह पूरी ऊंचाई तक नहीं फैला है ScrollView। मेरा लेआउट कुछ इस तरह दिखता है:

level    layout    layout_width    layout_height
1    LinearLayout    fill_parent    fill_parent
2    LinearLayout    fill_parent    wrap_content
3    (some irrelevant stuff)
2    ScrollView      fill_parent    fill_parent <-- this expands full height
3    LinearLayout    fill_parent    fill_parent <-- this does not (has orientation=vertical)
(following stuff probably are irrelevant, but just to be sure:)
4    TextView        fill_parent    fill_parent
4    LinearLayout    fill_parent    wrap_content

मैं देख सकता हूं कि ग्रहण LinearLayoutकी ScrollViewवजह से पूर्ण ऊंचाई का विस्तार नहीं होता है Android Layout Editor, अगर मैं ScrollView(आउटलाइन पैनल में) का चयन करता हूं तो इसे लाल सीमा के साथ हाइलाइट किया जाता है जो स्क्रीन को नीचे तक भरता है लेकिन जब मैं LinearLayoutइसके हाइलाइट का चयन करता हूं स्क्रीन के नीचे तक विस्तार नहीं करता है। मैं ऐसा करने के लिए कैसे प्राप्त कर सकता हूं?

मैं जो प्रभाव हासिल करने की कोशिश कर रहा हूं, उसमें कुछ पाठ और उसके नीचे एक बटन है ( LinearLayoutस्तर 4 में अंदर सिर्फ एक बटन है)। स्क्रॉलबार की आवश्यकता के लिए पाठ काफी बड़ा हो सकता है, जिस स्थिति में मैं चाहता हूं कि उपयोगकर्ता को बटन देखने के लिए नीचे स्क्रॉल करना पड़े। यदि स्क्रॉल पट्टी के लिए पाठ पर्याप्त बड़ा नहीं है, तो मैं चाहता हूं कि LinearLayoutबटन स्क्रीन के निचले हिस्से से चिपके रहे।

पहले तो मुझे लगा कि मुझे पूरा XML पोस्ट नहीं करना चाहिए क्योंकि यह आमतौर पर एक प्रश्न में कोड का एक बड़ा हिस्सा देखने के लिए एक मोड़ है। हालांकि, ऐसा लगता है कि यह आवश्यक हो सकता है, इसलिए यहां पूर्ण लेआउट है।

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/video_layout"
        android:focusable="true"
        style="@style/VideoLayout">
        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:foreground="@android:drawable/ic_media_play"
            android:foregroundGravity="center">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/video_thumb"
                android:padding="5dip"
                android:background="#454545"/>
        </FrameLayout>
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:focusable="true"
            style="@style/VideoTitle"
            android:id="@+id/video_title"
            android:layout_gravity="center"
            android:layout_weight="1"/>
    </LinearLayout>
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <!-- this ScrollView expands the full height of the screen.
             However, the next LinearLayout does not expand the full height of the ScrollView -->
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:layout_gravity="fill"
            android:orientation="vertical"
            android:id="@+id/info_layout">
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/info_body"
                style="@style/InfoText"/>
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                style="@android:style/ButtonBar">
                    <Button
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_weight="1"
                        android:text="@string/button_readmore"
                        android:id="@+id/btn_read_more"/>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

फिलहाल मैंने android:layout_gravity="bottom"समस्याग्रस्त का सहारा लिया है LinearLayout, जो कि स्क्रीन के नीचे बटन को चिपका देता है , चाहे कुछ भी हो। लेकिन यह भी पाठ को स्क्रीन के निचले हिस्से में चिपका देता है, जो कि वास्तव में मेरे बाद नहीं था।

अद्यतन: खरोंच, android:layout_gravity="bottom"जो ScrollViewकरने में असमर्थ, अच्छी तरह से, स्क्रॉल। अन्य विचार?

जवाबों:


956

अंत में स्वयं समाधान पाया। समस्या के साथ नहीं था LinearLayout, लेकिन ScrollView(अजीब लगता है, इस तथ्य को देखते हुए कि विस्तार हो रहा ScrollView था , जबकि LinearLayoutनहीं था)।

समाधान का उपयोग android:fillViewport="true"करना था ScrollView


4
ध्यान दें कि LinearLayout लंबवत रूप से विस्तारित होगा, लेकिन यह आवश्यक रूप से आपके लेआउट में परिलक्षित नहीं हो सकता है जब तक कि इसमें एक नियंत्रण नहीं होता है जो उस अतिरिक्त स्थान का उपयोग करता है android:weight
पॉल लामर्ट्स्मा

यह वास्तव में मदद करता है। उसके लिए धन्यवाद। लेकिन इस कोड के बिना कभी-कभी अच्छा काम करता है। तुम जानते हो क्यों?
अशोकचक्रवर्ती नागराजन

<LinearLayout एंड्रॉइड: लेआउट_प्रकार = "fill_parent" एंड्रॉइड: लेआउट_हाइट = "wra_content" Android: fillViewport = "true" android: background = "# 000" एंड्रॉइड: ओरिएंटेशन = "वर्टिकल"> </ LinearLayout>
प्रसाद

3
इसलिए बीमार मैं घंटों तक बैठा रहा और अपने कोड के साथ गलत खोज रहा था। किस लिए यह परमार्थ? जब आप कभी इसे गलत सेट करना चाहेंगे?
MyWay

@प्रसाद माता
goonerDroid

22

मुझे पता है कि यह पोस्ट बहुत पुरानी है, उन लोगों के लिए जो android:fillViewport="true"इसका उपयोग नहीं करना चाहते हैं क्योंकि यह कभी-कभी कीबोर्ड के ऊपर edittext नहीं लाता है। रैखिक लेआउट के बजाय सापेक्ष लेआउट का उपयोग करें यह उद्देश्य को हल करता है।


8

क्या आप अपना लेआउट xml प्रदान कर सकते हैं? ऐसा करने से लोगों को कम से कम प्रयास के साथ समस्या को फिर से बनाने में मदद मिलेगी।

आपको सेट करना पड़ सकता है

android:layout_weight="1"

उस आइटम के लिए जिसे आप विस्तारित करना चाहते हैं


1
आपके उत्तर के लिए धन्यवाद। मैंने आपके सुझाव की कोशिश की लेकिन यह काम नहीं किया। मैंने लेआउट xml को शामिल करने के लिए अपना प्रश्न भी अपडेट किया।
फेलिक्स

3

समाधान का उपयोग करना है

android:fillViewport="true"

पर स्क्रॉल दृश्य और प्रयोग करने में इसके अलावा कोशिश

"wrap_content"के बजाय "fill_parent"के रूप में"fill_parent"

अब पदावनत कर दिया गया है।


2

मैंने इसे प्राप्त करने के लिए गतिशील रूप से उपयोग किया है। मेरे पास एक LinearLayout है और इसके भीतर एक बच्चे के रूप में इस्तेमाल किया स्क्रॉल। फिर मैं फिर से LinearLayout को लेता हूं और जो भी कभी View u आप इस LinearLayout को जोड़ना चाहते हैं उसे जोड़ते हैं और फिर यह LinearLayout ScrollView में जोड़ते हैं और आखिर में इस स्क्रॉल दृश्य को LinearLayout में जोड़ते हैं। फिर यू को स्क्रॉल स्क्रॉल में यू मिल सकता है और कुछ भी दिखाई नहीं देगा।

LinearLayout (पेरेंट) - ScrollView (लाइनरलेयूट का बच्चा) - LinearLayout (स्क्रॉलव्यू का बच्चा) - यहाँ पर टेक्स्टव्यू, बटन्स, स्पिनर आदि जोड़िए जो आप चाहते हैं। फिर इस LinearLyout को ScrollView में जोड़ें। स्क्रॉल करने के लिए लागू केवल BILz एक CHILD और अंतिम रूप से इस स्क्रॉल दृश्य को LinearLyout में जोड़ें। यदि परिभाषित क्षेत्र स्क्रीन के आकार से अधिक है तो u को स्क्रॉल दृश्य के भीतर एक स्क्रॉल मिलेगा।


लेकिन यह समाधान xml को अधिक जटिल बनाता है, और फुलाए जाने में अधिक समय लेता है।
twlkyao

1

मेरे मामले में मैंने नहीं दिया है

रेखीय लयआउट (स्क्रॉलव्यूज़ चाइल्ड) का उन्मुखीकरण

इसलिए डिफ़ॉल्ट रूप से इसे क्षैतिज रूप से लिया जाता है, लेकिन स्क्रॉलव्यू स्क्रोल को लंबवत रूप से लेता है, इसलिए कृपया जांचें कि क्या 'Android: ओरिएंटेशन = "वर्टिकल" आपके स्क्रॉलव्यू के चाइल्ड पर सेट है (लीनियरलेउट के मामले में)।

यह मेरा मामला था उम्मीद है कि यह किसी की मदद करता है

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.