i am new in android and i am developing application . I have read in the developers.google.com that if i want the application screen compatible then my icons should be in ldpi , mdpi , hdpi , xhdpi and android itself will pick is it like this ? if not then what i have to do making it screen compatible and also how to give the dynamic padding ? like right now my code is look like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash_page"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:gravity="center_vertical">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="600dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/icon_login_btn"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="40dp"
android:background="@drawable/icon_btn_register" />
</LinearLayout>
</RelativeLayout>
So , you see here i have give the margin top , but that work only on tablets not on large screen mobiles.
see if u want to go with layout format that you have to make some drawable like
1.drawable-hdpi
2.drawable-large
3.drawable-ldpi
4.drawable-xhdpi
5.drawable-xlarge-mdpi
6.drawable-xxhdpi
and make all layout respectively then your app is going fine on any mobile tablet blue stack AOC android device
if u go with java code then
int density= getResources().getDisplayMetrics().densityDpi;
if(density==DisplayMetrics.DENSITY_HIGH)
System.out.println("Density is high");
if(density==DisplayMetrics.DENSITY_XXHIGH)
System.out.println("Density is xxhigh");
if(density==DisplayMetrics.DENSITY_XXXHIGH)
System.out.println("Density is xxxhigh");
if(density==DisplayMetrics.DENSITY_TV)
System.out.println("Density is Tv");
if(widthDp==600)
{
imageWidth = ;
imgHeight = ;
margin = ;
}
else if (widthDp==720)
{
}
else if(density==DisplayMetrics.DENSITY_XHIGH)
{
imageWidth = ;
imgHeight = ;
margin = ;
}
else if(density==DisplayMetrics.DENSITY_LOW)
{
imageWidth = ;
imgHeight = ;
margin = ;
}
else if(density==DisplayMetrics.DENSITY_MEDIUM)
{
imageWidth = ;
imgHeight = ;
margin = ;
}
else
{
imageWidth = ;
imgHeight = ;
margin = ;
}
do what ever way u like :)
BEST OF LUCK DUDE :)
For screen compatibility we can create folders like layout-large, layout-small under res folder and paste all the layouts in each folder and adjust according to the screen size. About icons we need to make different size icons and put it in respective folder .
Try using dimen.xml files. There you can define values for different screen sizes
/res/values/dimen.xml :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="margin_top">600dp</dimen>
</resources>
/res/values-large/dimen.xml :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="margin_top">800dp</dimen>
</resources>
and in your layout use
android:layout_marginTop="@dimen/margin_top"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.