Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Android

Android में लेआउट को वर्टिकली स्क्रॉलेबल कैसे बनाएं?

Android में ScrollView से वर्टिकल स्क्रॉलिंग

ScrollView एक व्यू ग्रुप है जो अपने सिंगल चाइल्ड को वर्टिकली स्क्रॉल करने योग्य बनाता है। कंटेंट स्क्रीन से बड़ा होने पर उपयोगी।

चरण 1: प्रोजेक्ट बनाएं

Android Studio: File → New Project।

चरण 2: लेआउट (activity_main.xml) - ScrollView के साथ

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/rootLayout">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="16dp">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:background="#C1C1C1"
                android:src="@drawable/a"
                android:scaleType="centerCrop"
                android:contentDescription="Image A" />

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:layout_marginTop="30dp"
                android:background="#C1C1C1"
                android:src="@drawable/b"
                android:scaleType="centerCrop"
                android:contentDescription="Image B" />

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:layout_marginTop="30dp"
                android:background="#C1C1C1"
                android:src="@drawable/c"
                android:scaleType="centerCrop"
                android:contentDescription="Image C" />

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:layout_marginTop="30dp"
                android:background="#C1C1C1"
                android:src="@drawable/d"
                android:scaleType="centerCrop"
                android:contentDescription="Image D" />

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:layout_marginTop="30dp"
                android:background="#C1C1C1"
                android:src="@drawable/e"
                android:scaleType="centerCrop"
                android:contentDescription="Image E" />

        </LinearLayout>

    </ScrollView>

</LinearLayout>

मुख्य बिंदु:

  • सिंगल चाइल्ड: ScrollView का केवल **एक** डायरेक्ट चाइल्ड हो सकता है (यहां LinearLayout)
  • fillViewport="true": चाइल्ड को व्यूपोर्ट जितना ऊंचा बनाता है अगर कंटेंट छोटा हो
  • वर्टिकल ओनली: क्षैतिज स्क्रॉल के लिए HorizontalScrollView उपयोग करें
  • नेस्टिंग न करें: ScrollView के अंदर ListView/RecyclerView न डालें

RecyclerView के साथ NestedScrollView (मॉडर्न):

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout ...>
        <!-- अन्य व्यूज -->
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:nestedScrollingEnabled="false" />
    </LinearLayout>

</androidx.core.widget.NestedScrollView>

आउटपुट

Android में लेआउट को वर्टिकली स्क्रॉलेबल कैसे बनाएं?

Android में लेआउट को वर्टिकली स्क्रॉलेबल कैसे बनाएं?

Android में लेआउट को वर्टिकली स्क्रॉलेबल कैसे बनाएं?

नतीजा: 5 बड़ी इमेजेस वर्टिकली स्क्रॉल होती हैं।

  1. Android ऐप में GridView लेआउट कैसे बनाएं? Android ऐप में GridView लेआउट कैसे बनाएं?

    Android में GridView और कस्टम एडाप्टर के साथ ग्रिड लेआउट यह उदाहरण दर्शाता है कि GridView और कस्टम BaseAdapter का उपयोग करके इमेज और टेक्स्ट का ग्रिड लेआउट कैसे बनाया जाए। चरण 1: नया प्रोजेक्ट बनाएं Android Studio में File → New Project चुनें। चरण 2: मेन लेआउट (res/layout/activity_main.xml) <?x

  1. एंड्रॉइड में बटन कैसे हटाएं या अदृश्य करें? एंड्रॉइड में बटन कैसे हटाएं या अदृश्य करें?

    View.VISIBLE, INVISIBLE, GONE के साथ बटन विजिबिलिटी कंट्रोल यह उदाहरण दर्शाता है कि setVisibility() का उपयोग करके बटन को अदृश्य (INVISIBLE) या पूरी तरह से हटाएं (GONE) कैसे करें। चरण 1: नया प्रोजेक्ट बनाएं Android Studio में File → New Project चुनें। चरण 2: लेआउट में दो बटन res/layout/activity_mai

  1. Android लेआउट्स में मास्टरी: अपने ऐप के लिए सही लेआउट चुनें Android लेआउट्स में मास्टरी: अपने ऐप के लिए सही लेआउट चुनें

    Linear, Relative, Constraint, Table, Frame और भी बहुत कुछ। जब आप अपने ऐप्लिकेशन को डिज़ाइन करना चाहते हैं तो Android ऐप्लिकेशन्स के पास चुनने के लिए ढेर सारे लेआउट्स होते हैं। सवाल यह है कि सबसे अच्छा कौन सा है?विभिन्न लेआउट्स की डिटेल में जाने से पहले, हम पहले व्यू ऑब्जेक्ट हायरार्की और Android की