Create dimen.xml
for following folder as per your requirement:
values
values-hdpi
values-ldpi
values-mdpi
values-sw600dp
values-sw720dp-land
etc...
and code for that dimen.xml
and give xxxdp
as you want:
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="button_width">300dp</dimen>
<dimen name="button_height">300dp</dimen>
</resources>
then after you xml
file like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/button"
android:layout_width="@dimen/button_width"
android:layout_height="@dimen/button_height"
android:text="OK"
android:layout_centerInParent="true" />
</LinearLayout>
FOR PROGRAMMATICALLY:
This also works:
getResources().getDisplayMetrics().density;
This will give you:
- 0.75 - ldpi
- 1.0 - mdpi
- 1.5 - hdpi
- 2.0 - xhdpi
- 3.0 - xxhdpi
- 4.0 - xxxhdpi
May it'll be Helpful...
Thanks...