我正在开发一个Android应用程序,我必须支持所有不同的屏幕尺寸和密度.所以我为布局创建了不同的文件夹:layout-small layout-large和layout.
然后我为图像创建了不同的文件夹:ldpi, mdpi和hdpi.在所有可绘制文件夹中,图像必须具有不同的大小?我问这个原因我有一个屏幕尺寸大且密度适中的手机,显示的图像会更小而且尺寸不合适?
Utt*_*tam 77
对于不同的屏幕尺寸,以下是应用程序中的资源目录列表,它为不同的屏幕尺寸和不同的位图可绘制提供不同的布局设计,适用于小型,中型,高密度和超高密度屏幕.
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
Run Code Online (Sandbox Code Playgroud)
Manifest中的以下代码支持所有dpis.
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
Run Code Online (Sandbox Code Playgroud)
并查看我的答案.
Sch*_*esi 11
从Android 3.2(API级别13)开始,不推荐使用大小组(文件夹small,normal,large,xlarge),以支持基于可用屏幕宽度管理屏幕大小的新技术.
当涉及到支持多种屏幕尺寸时,听起来不错。以下提供了更好的结果。
res/layout/layout-w120dp
res/layout/layout-w160dp
res/layout/layout-w240dp
res/layout/layout-w160dp
res/layout/layout-w320dp
res/layout/layout-w480dp
res/layout/layout-w600dp
res/layout/layout-w720dp
Run Code Online (Sandbox Code Playgroud)
使用显示指标检查设备的宽度和高度
放置/显示哪种布局适合设备的最终宽度。
let smallestScreenWidthDp="assume some value(Which will be derived from Display metrics)"
Run Code Online (Sandbox Code Playgroud)
应该在setContentView()之前检查所有内容,否则会遇到麻烦
Configuration config = getResources().getConfiguration();
Configuration config = getResources().getConfiguration();
if (config.smallestScreenWidthDp >= 600) {
setContentView(R.layout.layout-w600dp);
} else {
setContentView(R.layout.main_activity);
}
Run Code Online (Sandbox Code Playgroud)
在顶部,我已经创建了许多布局以适合多个屏幕,这取决于您,可能与不取决于您。您可以从Play商店查看哪个API的评论,下载量很高。 。
我希望它对您有帮助。很少使用一些第三方库,这可能会减少您的工作量,但这不是最佳实践。习惯于Android最佳做法。
| 归档时间: |
|
| 查看次数: |
103052 次 |
| 最近记录: |