Android में डॉटेड/डैश्ड लाइन बनाना: सरल तरीका
यह उदाहरण दर्शाता है कि Android में डॉटेड/डैश्ड लाइन कैसे बनाएं।
चरण 1 - नया प्रोजेक्ट बनाएं
Android Studio में एक नया प्रोजेक्ट बनाएं: File → New Project पर जाएं और नया प्रोजेक्ट बनाने के लिए सभी आवश्यक विवरण भरें।
चरण 2 - activity_main.xml लेआउट
res/layout/activity_main.xml में निम्न कोड जोड़ें:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="https://schemas.android.com/apk/res/android"
android:id="@+id/parent"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:gravity="center"
android:background="#33FFFF00"
android:orientation="vertical">
<TextView
android:id="@+id/text"
android:textSize="18sp"
android:textAlignment="center"
android:text="click to show toast at top"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="5dp"
android:src="@drawable/dotted"
android:layerType="software" />
</LinearLayout>
उपरोक्त कोड में, हमारे पास टेक्स्ट व्यू के साथ इमेज व्यू है। इमेज व्यू में डॉटेड बैकग्राउंड होता है। इसलिए नीचे दिखाए अनुसार drawable में dotted.xml बनाएं:
dotted.xml (drawable फोल्डर में)
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="https://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/white" />
<stroke
android:width="1dip"
android:color="#4fa5d5"
android:dashWidth="5dp"
android:dashGap="3dp"/>
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp"/>
</shape>
नोट: डॉटेड/डैश्ड लाइन के लिए `
चरण 3 - MainActivity.java
src/MainActivity.java में निम्न कोड जोड़ें:
package com.example.andy.myapplication;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int view = R.layout.activity_main;
TextView text;
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(view);
text = findViewById(R.id.text);
text.setText("डॉटेड लाइन टेक्स्ट व्यू के लिए");
}
}
आइए अपने एप्लिकेशन को चलाने का प्रयास करें। मान लें कि आपने अपने वास्तविक Android मोबाइल डिवाइस को कंप्यूटर से जोड़ा है। Android Studio से ऐप चलाने के लिए, अपनी प्रोजेक्ट की एक्टिविटी फ़ाइलों में से एक खोलें और टूलबार से Run आइकन पर क्लिक करें। विकल्प के रूप में अपना मोबाइल डिवाइस चुनें और फिर अपने मोबाइल डिवाइस की जांच करें जो आपकी डिफ़ॉल्ट स्क्रीन प्रदर्शित करेगा।

उपरोक्त परिणाम में एक डॉटेड लाइन है।