Android में मार्की (स्क्रॉलिंग) टेक्स्ट बनाने का गाइड
यह ट्यूटोरियल दिखाता है कि कैसे TextView में लंबे टेक्स्ट को क्षैतिज रूप से स्क्रॉल (मार्की प्रभाव) कराया जाए।
चरण 1: नया प्रोजेक्ट बनाएं
Android Studio में File → New Project चुनकर नया प्रोजेक्ट बनाएं।
चरण 2: लेआउट फ़ाइल में कोड जोड़ें
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">
<TextView
android:padding="4dp"
android:id="@+id/textMarquee"
android:textSize="24sp"
android:textStyle="bold|italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"/>
</RelativeLayout>
महत्वपूर्ण एट्रिब्यूट्स की व्याख्या
android:singleLine="true"- टेक्स्ट को एक ही लाइन में रखता हैandroid:ellipsize="marquee"- मार्की प्रभाव सक्षम करता हैandroid:marqueeRepeatLimit="marquee_forever"- अनंत बार दोहराता हैandroid:scrollHorizontally="true"- क्षैतिज स्क्रॉलिंग सक्षम करता है
चरण 3: MainActivity.java में कोड जोड़ें
src/MainActivity.java में:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView textMarquee;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textMarquee = findViewById(R.id.textMarquee);
textMarquee.setText("Be the change that you wish to see in the world, Be yourself; everyone else is already taken.");
textMarquee.setSelected(true); // मार्की शुरू करने के लिए महत्वपूर्ण!
}
}
महत्वपूर्ण नोट
textMarquee.setSelected(true) कॉल करना आवश्यक है, अन्यथा मार्की एनिमेशन शुरू नहीं होगी।
चरण 4: 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>
ऐप चलाएं
डिवाइस कनेक्ट करें, Run आइकन पर क्लिक करें और मोबाइल पर लगातार स्क्रॉल होता टेक्स्ट देखें।