কম্পিউটার টিউটোরিয়াল

অ্যান্ড্রয়েড সিকোয়েন্স লেআউট ব্যবহার করার পদ্ধতি

অ্যান্ড্রয়েড সিকোয়েন্স লেআউট সম্পর্কে জানার আগে এটি কী সেটা বুঝতে হবে। সিকোয়েন্স লেআউটে প্রগ্রেস বারের সাথে ধাপে ধাপে একটি সিকোয়েন্স থাকে। এনিমেটেড প্রগ্রেস বার সিকোয়েন্স অনুযায়ী কাজ করে।

এই উদাহরণটি দর্শায় কীভাবে অ্যান্ড্রয়েড সিকোয়েন্স লেআউট ব্যবহার করা যায়।

ধাপ ১: নতুন প্রজেক্ট তৈরি করুন

অ্যান্ড্রয়েড স্টুডিওতে File → New Project এ যান এবং প্রজেক্ট তৈরির জন্য প্রয়োজনীয় বিবরণ পূরণ করুন।

ধাপ ২: build.gradle(app)-এ ডিপেন্ডেন্সি যোগ করুন

apply plugin: 'com.android.application'
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.andy.myapplication"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    implementation 'com.github.transferwise:sequence-layout:1.0.7'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

ধাপ ৩: build.gradle(project)-এ রিপোজিটরি যোগ করুন

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
}
allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

ধাপ ৪: activity_main.xml-এ লেআউট কোড যোগ করুন

<?xml version="1.0" encoding="utf-8"?>
<com.transferwise.sequencelayout.SequenceLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:app="https://schemas.android.com/apk/res-auto">
    <com.transferwise.sequencelayout.SequenceStep
        android:id="@+id/first"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:subtitle="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s."
        app:anchor="30 Nov"
        app:title="First step"/>
    <com.transferwise.sequencelayout.SequenceStep
        android:id="@+id/second"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:subtitle="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s."
        app:title="Second step"/>
    <com.transferwise.sequencelayout.SequenceStep
        android:id="@+id/third"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:anchor="Today"
        app:title="Third step"
        app:subtitle="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s" />
</com.transferwise.sequencelayout.SequenceLayout>

উপরোক্ত কোডে SequenceLayout প্যারেন্ট হিসেবে এবং SequenceStep প্রতিটি ধাপ হিসেবে ডিক্লেয়ার করা হয়েছে। প্রতিটি ধাপে অ্যাঙ্কর ভিউ, টাইটেল ও সাবটাইটেল থাকে।

ধাপ ৫: MainActivity.java-এ লজিক লিখুন

package com.example.andy.myapplication;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
import com.transferwise.sequencelayout.SequenceStep;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    SequenceStep sequenceStep, sequenceStep2, sequenceStep3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        sequenceStep = findViewById(R.id.first);
        sequenceStep2 = findViewById(R.id.second);
        sequenceStep3 = findViewById(R.id.third);
        sequenceStep2.setActive(true);
        sequenceStep.setOnClickListener(this);
        sequenceStep2.setOnClickListener(this);
        sequenceStep3.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.first:
                Toast.makeText(MainActivity.this, "This is first step", Toast.LENGTH_LONG).show();
                break;
            case R.id.second:
                Toast.makeText(MainActivity.this, "This is second step", Toast.LENGTH_LONG).show();
                break;
            case R.id.third:
                Toast.makeText(MainActivity.this, "This is Third step", Toast.LENGTH_LONG).show();
                break;
        }
    }
}

এখানে সিকোয়েন্স স্টেপ ডিক্লেয়ার করে OnClickListener দেওয়া হয়েছে। স্টেপ এক্টিভ করার জন্য:

sequenceStep2.setActive(true);

এই কোডে sequenceStep2 এক্টিভ করা হয়েছে, অর্থাৎ প্রগ্রেস বার সিকোয়েন্স স্টেপ ২ পর্যন্ত দেখাবে।

আউটপুট

অ্যাপ রান করুন। আউটপুট নিচের চিত্রের মত হবে:

অ্যান্ড্রয়েড সিকোয়েন্স লেআউট ব্যবহার করার পদ্ধতি

যেহেতু এক্টিভ মোড ডিক্লেয়ার করা হয়েছে, তাই প্রগ্রেস বার দেখাচ্ছে।

  1. অ্যান্ড্রয়েডে LocalBroadcastManager ব্যবহারের পদ্ধতি

  2. অ্যান্ড্রয়েডে Handler ব্যবহারের পদ্ধতি

  3. RecyclerView-এ ConstraintLayout ব্যবহারের পদ্ধতি

  4. এন্ড্রয়েডে ViewFlipper ব্যবহার করার পদ্ধতি