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

Android में ScrollView का उपयोग कैसे करें?

Android में ScrollView का उपयोग

यह उदाहरण दर्शाता है कि लंबी सामग्री को स्क्रॉल करने योग्य बनाने के लिए ScrollView का उपयोग कैसे करें।

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

Android Studio में File → New Project से प्रोजेक्ट बनाएं।

चरण 2: ScrollView में कई बटन जोड़ें (activity_main.xml)

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:tools="https://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16sp"
    android:scrollbarSize="25sp"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="8dp"
        android:gravity="center_horizontal">

        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 1" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 2" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 3" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 4" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 5" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 6" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 7" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 8" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 9" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 10" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 11" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 12" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 13" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 14" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 15" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 16" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 17" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 18" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 19" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="बटन 20" />

    </LinearLayout>
</ScrollView>

चरण 3: MainActivity.java (सरल)

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

चरण 4: AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
    package="com.example.scrollviewdemo">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

ऐप चलाएं

डिवाइस कनेक्ट करें और Run दबाएं। 20 बटनों की लंबी सूची स्क्रॉल करके देखें।

Android में ScrollView का उपयोग कैसे करें?

  1. Android SQLite में total_changes() फंक्शन का उपयोग कैसे करें? Android SQLite में total_changes() फंक्शन का उपयोग कैसे करें?

    SQLite total_changes() फंक्शन उदाहरण से पहले, Android में SQLite डेटाबेस को समझें। SQLite एक ओपन-सोर्स SQL डेटाबेस है जो डिवाइस पर टेक्स्ट फ़ाइल में डेटा स्टोर करता है। total_changes() फंक्शन डेटाबेस कनेक्शन खुलने के बाद से हुए कुल पंक्ति परिवर्तनों (इन्सर्ट, अपडेट, डिलीट) की संख्या लौटाता है। चरण

  1. Android SQLite में unlikely() फंक्शन का उपयोग कैसे करें? Android SQLite में unlikely() फंक्शन का उपयोग कैसे करें?

    SQLite unlikely() फंक्शन उदाहरण से पहले, Android में SQLite डेटाबेस को समझें। SQLite एक ओपन-सोर्स SQL डेटाबेस है। unlikely(X) फंक्शन SQLite क्वेरी ऑप्टिमाइज़र को एक संकेत देता है कि एक्सप्रेशन X के झूठे होने की संभावना अधिक है। यह क्वेरी प्लानिंग में मदद करता है। यह likely() का विपरीत है। चरण 1: नय

  1. एंड्रॉइड में SharedPreferences का उपयोग कैसे करें? एंड्रॉइड में SharedPreferences का उपयोग कैसे करें?

    एंड्रॉइड में SharedPreferences — की-वैल्यू डेटा स्टोर करने का आसान तरीका SharedPreferences एंड्रॉइड में छोटे प्राइमिटिव डेटा (बूलियन, इंट, फ्लोट, लॉन्ग, स्ट्रिंग, स्ट्रिंग सेट) को XML फाइल में प्राइवेटली स्टोर करने का मानक API है। यह रिमेंबर मी लॉगिन, यूज़र सेटिंग्स, ऑनबोर्डिंग फ्लैग आदि के लिए आदर्