我是android的新手,我正在开发应用程序。我在developers.google.com上看过如果我希望应用程序屏幕兼容,那么我的图标应该是ldpi,mdpi,hdpi,xhdpi和android本身会选择这样吗?如果不是那么我必须做什么使它与屏幕兼容,以及如何给动态填充?就像现在我的代码看起来像这样
<?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>
所以,你看到我在这里给了保证金最高,但这只适用于不在大屏幕手机上的平板电脑。
答案 0 :(得分:1)
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 :)
答案 1 :(得分:0)
为了屏幕兼容性,我们可以在res文件夹下创建layout-large,layout-small等文件夹,并粘贴每个文件夹中的所有布局,并根据屏幕大小进行调整。 关于图标我们需要制作不同大小的图标并将其放在相应的文件夹中。
答案 2 :(得分:0)
尝试使用 dimen.xml 文件。您可以在那里定义不同屏幕尺寸的值
/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>
并在您的布局中使用
android:layout_marginTop="@dimen/margin_top"