
1>How我看到的屏幕是这样的,在不同的屏幕大小?
2>what是我必须遵循的步骤吗?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.sridhar.textviewautosize.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="36dp"
android:layout_marginTop="25dp"
android:autoSizeTextType="uniform"
android:text="Hello World I am Checking AutoFill Text View is working or not for different screens" />
</LinearLayout>请检查这段代码,并告诉我如何根据小、中、大和xlarge的屏幕大小自动调整这个边距、左和右边距属性。
发布于 2018-02-01 04:05:25
您需要设置hdpi,xhdpi等,它将覆盖所有的电话大小。在资源内部设置dimensions.xml。
例如:res/values hdpi/量纲s.xml,res/values xhdpi/量纲. For
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">10dp</dimen>
<dimen name="activity_vertical_margin">20dp</dimen>
发布于 2018-02-01 03:58:56
应该在不同的values文件夹中定义页边距,如下所示:

如果您需要支持更多的屏幕大小,您可以添加任意数量的sw文件夹。您可以从下面的图像计算sw dp:

->附件4: 768/2 =384 160,nexus 5: 1080/3 =360,像素2: 1080 * 160/420 =410 160。
发布于 2018-02-01 07:03:09
使用此方法可获得屏幕大小。
public void get_screen_size(){
int screenSize = getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK;
switch(screenSize) {
case Configuration.SCREENLAYOUT_SIZE_XLARGE:
Toast.makeText(this, "Extra Large Screen", Toast.LENGTH_LONG).show();
break;
case Configuration.SCREENLAYOUT_SIZE_LARGE:
Toast.makeText(this, "Large Screen", Toast.LENGTH_LONG).show();
break;
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
Toast.makeText(this, "Normal Screen", Toast.LENGTH_LONG).show();
break;
case Configuration.SCREENLAYOUT_SIZE_SMALL:
Toast.makeText(this, "Small Screen", Toast.LENGTH_LONG).show();
break;
default:
Toast.makeText(this, "Screen size is not xlarge, large, normal or small", Toast.LENGTH_LONG).show();
}
}然后根据实际屏幕大小,应用您认为需要programmatically.的边距。
然而,我建议您避免使用所有的空白,而是找到另一种解决方案,也许使用权重,这样它就可以在任何屏幕上工作。
当然,最好的解决方案是遵循android支持不同屏幕大小的建议,如下所示:
https://developer.android.com/training/multiscreen/screensizes.html
https://stackoverflow.com/questions/48555043
复制相似问题