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

Android-এ বিভিন্ন স্ক্রিন সাইজ সাপোর্ট করার পদ্ধতি

অ্যান্ড্রয়েডে বিভিন্ন স্ক্রিন আকার সমর্থন করা

এই উদাহরণটি দেখায় কিভাবে Android-এ বিভিন্ন স্ক্রিন আকারের জন্য অ্যাপটি অডাপ্ট করা যায়। এখানে ডিভাইসের স্ক্রিন ডায়মেনশন (dp-এ) প্রোগ্রামেটিক্যালি নির্ণয় করার পদ্ধতি দেখানো হয়েছে।

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

Android Studio-তে File → New Project এ যান এবং প্রয়োজনীয় বিবরণ পূরণ করে একটি নতুন প্রজেক্ট তৈরি করুন।

ধাপ ২: লেআউট XML-এ কোড যোগ করুন

res/layout/activity_main.xml ফাইলে নিচের কোডটি যোগ করুন:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:app="https://schemas.android.com/apk/res-auto"
    xmlns:tools="https://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/tv_screen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:textSize="14sp"
        tools:ignore="MissingConstraints" />

</androidx.constraintlayout.widget.ConstraintLayout>

ধাপ ৩: MainActivity.java-এ কোড যোগ করুন

package com.app.sample;

import androidx.appcompat.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.widget.TextView;
import android.os.Bundle;

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

        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);

        // পিক্সেল থেকে dp-এ রূপান্তর: dp = (px * 160) / dpi
        float dpWidth = (metrics.widthPixels * 160f) / metrics.xdpi;
        float dpHeight = (metrics.heightPixels * 160f) / metrics.ydpi;

        TextView tvScreen = findViewById(R.id.tv_screen);
        tvScreen.setText(String.format("Screen: %d dp x %d dp", (int) dpWidth, (int) dpHeight));
    }
}

ধাপ ৪: AndroidManifest.xml

স্ট্যান্ডার্ড ম্যানিফেস্ট কনফিগারেশন:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
    package="com.app.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 Studio-র Run বাটনে ক্লিক করুন। অ্যাপটি ডিভাইসের স্ক্রিন প্রস্থ ও উচ্চতা dp-এ দেখাবে।

Android-এ বিভিন্ন স্ক্রিন সাইজ সাপোর্ট করার পদ্ধতি

  1. অ্যান্ড্রয়েডে স্ক্রিন টাইম চেক করার পদ্ধতি

  2. অ্যান্ড্রয়েড স্ক্রিন পিসিতে কাস্ট করার পদ্ধতি

  3. Android-এ হোম স্ক্রিন অ্যাসাইন করার পদ্ধতি

  4. আপনার অ্যান্ড্রয়েড স্ক্রিন পিসিতে সিমলেসলি মিরর করুন: একটি সিম্পল ধাপে ধাপে গাইড