2010-08-05 15 views
139

गतिविधि शुरू करने के बाद मैं नीचे परिभाषित xml में अन्य बटन और विकल्पों को देखने के लिए नीचे स्क्रॉल करने में असमर्थ हूं।लाइनरलाइट स्क्रॉल करने योग्य कैसे बनाएं

क्या कोई यह स्क्रॉल करने योग्य बनाने के बारे में जानता है?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:background="#000044" 
android:isScrollContainer="true" 
android:orientation="vertical"> 
<TextView 
    android:id="@+id/title" 
    android:text="@string/title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#ffffff"/> 
<EditText 
    android:id="@+id/editTitle" 
    android:text="" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/> 
<TextView 
    android:id="@+id/description" 
    android:text="@string/description" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#ffffff"/> 
<EditText 
    android:id="@+id/editDescription" 
    android:text="" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/> 
<TextView 
    android:id="@+id/location" 
    android:text="@string/location" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#ffffff"/> 
<EditText 
    android:id="@+id/editLocation" 
    android:text="" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/> 
<TextView 
    android:id="@+id/startTime" 
    android:text="@string/startTime" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#ffffff"/> 
<DatePicker 
    android:id="@+id/DatePicker01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
<TimePicker 
    android:id="@+id/TimePicker01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
<TextView 
    android:id="@+id/endTime" 
    android:text="@string/endTime" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#ffffff"/> 
<DatePicker 
    android:id="@+id/DatePicker02" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
<TimePicker 
    android:id="@+id/TimePicker02" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
<Button 
    android:id="@+id/buttonCreate" 
    android:text="Create" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
</LinearLayout> 

मेरी कक्षा कोड

package com.example.blah; 

import android.app.Activity; 
import android.os.Bundle; 

public class example extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
    } 
} 

उत्पादन http://img265.imageshack.us/img265/7601/linearlayout.jpg

+0

संभावित डुप्लिकेट [आप लाइनरलाउट स्क्रॉल करने योग्य कैसे बनाते हैं?] (Http://stackoverflow.com/questions/4055537/how-do-you-make-a-linearlayout-scrollable) – Flow

उत्तर

204

प्लेस एक ScrollView में अपने लेआउट है।

+0

बिल्कुल सही जवाब! – Sana

+6

यह साइड इफेक्ट्स है, जैसे कि स्क्रॉलव्यू के अंदर स्क्रॉल करने योग्य तत्वों को सूचीदृश्य जैसे स्थानांतरित करने में सक्षम नहीं है। – JoaoFilipeClementeMartins

+2

आपको स्क्रॉल करने योग्य सामग्री के अंदर स्क्रॉल करने योग्य सामग्री से बचना चाहिए। उपयोगकर्ता इसे पसंद नहीं करेंगे (आप कभी नहीं जानते कि आप कौन सी स्क्रॉल करेंगे)। – Guillaume

62
<?xml version="1.0" encoding="utf-8"?> 
<ScrollView ...> 

<LinearLayout ...> 

... 
... 

</LinearLayout> 

</ScrollView> 
15

रेखीय लेआउट जो ScrollView अंदर रखा जाता है में अपने पूरे सामग्री रखो।

ScrollView अपने बच्चे के रूप में केवल एक लेआउट लेता है।

isScrollContainer="true" 

यह संपत्ति तब उपयोग की जाती है जब एंड्रॉइड में आपकी सॉफ्टकी पॉप हो जाती है और फिर भी आप अपना दृश्य स्क्रॉल करना चाहते हैं।

2

आप इसे View.scrollTo(..) का उपयोग करके भी कार्यान्वित कर सकते हैं।

postDelayed(new Runnable() { 
      public void run() { 

       counter = (int) (counter + 10); 
       handler.postDelayed(this, 100); 

        llParent.scrollTo(counter , 0); 
       } 

      } 
     }, 1000L); 
54
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center|left" 
     android:orientation="vertical"> 

     Your views go here... 

    </LinearLayout> 

</ScrollView> 
2

आप किसी भी लेआउट स्क्रॉल कर सकते हैं। बस <?xml version="1.0" encoding="utf-8"?> के तहत इन पंक्तियां जोड़ें:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

और अंत में जोड़ने के लिए एक गैर स्क्रॉल गतिविधि के </ScrollView>

उदाहरण:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:verticalScrollbarPosition="right" 
    tools:context="p32929.demo.MainActivity"> 


    <TextView 
     android:text="TextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="102dp" 
     android:id="@+id/textView" 
     android:textSize="30sp" /> 
</RelativeLayout> 

यह स्क्रॉल करने के बाद यह इस तरह हो जाता है:

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

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/activity_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     android:verticalScrollbarPosition="right" 
     tools:context="p32929.demo.MainActivity"> 


     <TextView 
      android:id="@+id/textView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="102dp" 
      android:text="TextView" 
      android:textSize="30sp" /> 
    </RelativeLayout> 
</ScrollView> 
1

चौड़ाई और एच के साथ स्क्रॉलव्यू के अंदर अपने सभी लेआउट रखें fill_parent करने के लिए आठ सेट।

+0

स्क्रॉल करेंगे, तब भी यह पक्ष पर एक बार दिखाएगा आपका उत्तर किसी उत्तर के बजाय टिप्पणी की तरह दिखता है। एक बार आपके पास पर्याप्त [प्रतिष्ठा] (http://stackoverflow.com/help/whats-reputation) हो जाने पर आप किसी भी पोस्ट पर [टिप्पणी] (http://stackoverflow.com/help/privileges/comment) करने में सक्षम होंगे। यह भी जांचें [इसके बजाय मैं क्या कर सकता हूं] (https: //meta.stackexchange।com/प्रश्न/214,173/क्यों करते हैं-ए-जरूरत-50-प्रतिष्ठा करने वाली टिप्पणी-क्या-कर सकते हैं-ए-do-बजाय)। यदि आप उत्तर देने का इरादा रखते हैं, तो गुणवत्ता जवाब प्रदान करने के लिए इसे [कैसे-जवाब दें] (http://stackoverflow.com/help/how-to-answer) पढ़ें। – thewaywewere

+0

fill_parent पहले से ही बहिष्कृत और match_parent के साथ प्रतिस्थापित –

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