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

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

परिचय

यह उदाहरण दर्शाता है कि Android में एक कार्यशील वर्टिकल (लंबवत) सीकबार कैसे प्राप्त करें। डिफ़ॉल्ट रूप से Android का SeekBar क्षैतिज होता है, लेकिन rotation विशेषता का उपयोग करके इसे आसानी से लंबवत बनाया जा सकता है।

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

Android Studio खोलें, File → New Project चुनें और आवश्यक विवरण भरकर एक नया प्रोजेक्ट बनाएं।

चरण 2: लेआउट XML में कोड जोड़ें

res/layout/activity_main.xml फ़ाइल में निम्नलिखित कोड जोड़ें:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".MainActivity">

    <SeekBar
        android:id="@+id/seekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:rotation="270"/>

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text=""
        android:textSize="16sp" />

</RelativeLayout>

चरण 3: MainActivity.java में लॉजिक जोड़ें

src/MainActivity.java फ़ाइल में निम्नलिखित कोड जोड़ें:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    SeekBar seekBar;
    TextView textView;
    int min = 0, max = 100, current = 50;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView = findViewById(R.id.textView);
        seekBar = findViewById(R.id.seekBar);

        seekBar.setProgress(max - min);
        seekBar.setProgress(current - min);
        textView.setText("" + current);

        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                current = progress + min;
                textView.setText("" + current);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) { }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) { }
        });
    }
}

चरण 4: AndroidManifest.xml कॉन्फ़िगर करें

सुनिश्चित करें कि आपके androidManifest.xml में मुख्य गतिविधि सही ढंग से घोषित है:

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

    <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>

ऐप चलाएं

अपने Android डिवाइस को कंप्यूटर से कनेक्ट करें। Android Studio में टूलबार से Run आइकन पर क्लिक करें, अपना डिवाइस चुनें, और ऐप लॉन्च होने पर आपको लंबवत सीकबार दिखाई देगा।

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

  1. Android में वर्तमान थ्रेड ID कैसे प्राप्त करें? Android में वर्तमान थ्रेड ID कैसे प्राप्त करें?

    Android में वर्तमान थ्रेड की ID प्राप्त करना उदाहरण में जाने से पहले, हमें पता होना चाहिए कि थ्रेड क्या है। एक थ्रेड एक हल्का सब-प्रोसेस है, यह UI को बाधित किए बिना बैकग्राउंड ऑपरेशन करने जा रहा है। यह उदाहरण दर्शाता है कि Android में वर्तमान थ्रेड ID कैसे प्राप्त करें। चरण 1: नया प्रोजेक्ट बनाएं A

  1. Android Spinner से चयनित मान (Value) कैसे प्राप्त करें? Android Spinner से चयनित मान (Value) कैसे प्राप्त करें?

    Android Spinner (ड्रॉपडाउन) से चयनित आइटम प्राप्त करना strings.xml में स्ट्रिंग ऐरे से Spinner भरकर OnItemSelectedListener से चयनित मान प्राप्त करने का तरीका। चरण 1: नया प्रोजेक्ट बनाएं Android Studio में File → New Project। चरण 2: लेआउट में Spinner res/layout/activity_main.xml: <?xml version=1

  1. एंड्रॉइड ऐप में फ्लिंग जेस्चर डिटेक्शन कैसे काम करें? एंड्रॉइड ऐप में फ्लिंग जेस्चर डिटेक्शन कैसे काम करें?

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