How Can We Detect Custom Screen Category In Android?
I would like to detect custom screen category in android being used in the particular activity,I would like to detect layout-sw640dp programatically,how can be this achieved.We can
Solution 1:
Not sure why you need to do that. But, a quick walk-around is to use tag, for example:
In mdpi:
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/content_bg"android:orientation="vertical"android:id="@+id/name"android:tag="mdpi-xxx-yyy" >
In hdpi:
android:id="@+id/name"
android:tag="hdpi-xxx-yyy" >
Then, read tag from your code for R.id.name.
Solution 2:
sw640dp
just means the smallest available dimension is at least 640dp. This is based off the available layout space for an activity, not the actual resolution of the device. So you can calculate this based off the dimensions of your root layout in the activity:
int density = getResources().getDisplayMetrics().density;
int widthDp = rootView.getWidth() / density;
int heightDp = rootView.getHeight() / density;
if(widthDp >= 640 || heightDp >= 640) {
// qualifies for sw640dp
}
else {
// does not qualify for sw640dp
}
In the case of the Galaxy S3, it's resolution is 1280x720, which is 640x360 converted to dp units. Since sw
pertains to the available dimensions of the layout, not the resolution, I'm guessing it would not qualify for sw640dp
since system decorations, such as the status bar, would reduce your layout's available height.
Post a Comment for "How Can We Detect Custom Screen Category In Android?"