मेरे लेआउट को नीचे स्क्रॉल करने में सक्षम कैसे करें?


88

मैं "रिप्लाइड बाय:" अनुभाग में डेटा देखने के लिए स्क्रीन को नीचे स्क्रॉल नहीं कर सकता। मैं अपने लेआउट को कैसे स्क्रॉल कर सकता हूं?

वैकल्पिक शब्द

जवाबों:


200

बस एक अंदर सभी लपेटो ScrollView:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <!-- Here you put the rest of your current view-->
</ScrollView>

जैसा कि डेविड हेडलंड ने कहा, ScrollView इसमें सिर्फ एक आइटम हो सकता है ... इसलिए यदि आपके पास ऐसा कुछ था:

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

आपको इसे बदलना होगा:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
        <!-- bla bla bla-->
    </LinearLayout>
</ScrollView>

15
+1। एक त्वरित टिप्पणी: ScrollViewक्या केवल एक ही बच्चा हो सकता है, इसलिए यदि आपके पास वर्तमान में बहुत सारे विचार हैं, तो आपको उन्हें एक दृश्य समूह में लपेटने की आवश्यकता है (कहते हैं LinearLayout)
डेविड हेडलंड

1
साभार @ दाविद हेडलंड
प्रतीक राज

मेरी समस्या को ठीक करने के लिए कृपया मुझे stackoverflow.com/questions/38588702/… पर
Karthi

40

संबंधित लेआउट के साथ स्क्रॉल दृश्य का उपयोग करने के लिए:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"> <!--IMPORTANT otherwise backgrnd img. will not fill the whole screen -->

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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:background="@drawable/background_image"
    >

    <!-- Bla Bla Bla i.e. Your Textviews/Buttons etc. -->
    </RelativeLayout>
</ScrollView>

1
व्यूपोर्ट टैग क्या है
रुचिर बैरोनिया

4

बस स्क्रॉल के अंदर वह सब लपेटें

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

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.ruatech.sanikamal.justjava.MainActivity">
<!-- Here you put the rest of your current view-->
</ScrollView>

0

अगर आपको ऊपर लिखी हुई चीज़ करने के बाद भी स्क्रॉल नहीं मिला है तो .....

सेट करें android:layout_height="250dp"या आप कह सकते हैं कि कोई संख्यात्मक मान xdpकहाँ xहो सकता है।


0

हाँ, यह बहुत सरल है। बस इसके अंदर अपना कोड डालें:

<androidx.core.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" 
    android:layout_height="match_parent">

//YOUR CODE

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