与多屏幕支持相关的布局问题
我正在尝试开发一个需要多屏幕支持的应用程序。我已阅读有关多屏幕支持最佳实践的 Android 文章。根据本文,我们必须遵循 3 件重要的事情:
- 在 AndroidManifest.xml 中提及对不同屏幕尺寸(大、中、小)和任何密度的支持。
- 将 3 dpi(120、160、240)的图像放置在 3 个文件夹 res/ldpi、res/mdpi 和 res/hdpi 中。
- 在布局中,尺寸应以“倾角”单位提及。然后 Android 将自行处理缩放。
我已经在我的项目中实现了所有这些要点。图像是从适当的文件夹中正确拾取的。但控制的安排并不相同。
例如,我在三个模拟器上运行该应用程序
1。分辨率240*320 dpi 120。
2。分辨率240*320 dpi 160。
3。分辨率240*320 dpi 240。
(所有模拟器具有相同的分辨率但不同的密度。)
问题是控件的位置在所有三个模拟器上都不相同。根据我的理解,如果 android:layout_marginLeft 和 android:layout_marginTop 在“dip”中提到,那么这个问题不应该发生。随着模拟器密度的增加,控件会更加靠右放置。
即使所有设备的布局都相同,我是否绝对有必要为屏幕尺寸和密度的所有组合提供布局?
我是否遗漏了一些重要的观点?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:src="@drawable/bgd" android:scaleType="fitXY">
</ImageView>
<ImageView android:id="@+id/wtButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/button" android:layout_marginLeft="170dip"
android:layout_marginTop="9dip"></ImageView>
<ImageView android:id="@+id/htButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/button2" android:layout_marginLeft="220dip"
android:layout_marginTop="90dip"></ImageView>
</RelativeLayout>
图片:
I am trying to develop an app for which I want multiple screen support. I have read the Android article on Best practices for Multiple Screen Support. As per the article we have to follow 3 important things:
- Mention support for different screen sizes(large, medium and small) and any density in AndroidManifest.xml.
- Place images of 3 dpi's (120, 160, 240) in 3 folders res/ldpi, res/mdpi and res/hdpi.
- In layout's the dimension should be mentioned in "dip" units. Then Android will take care of the scaling on its own.
I have implemented all these points in my project. The images are picked up correctly from the appropriate folders. But the arrangements of the controls in not same.
e.g. I ran the app on three emulators
1. Resolution 240*320 dpi 120.
2. Resolution 240*320 dpi 160.
3. Resolution 240*320 dpi 240.
(All the emulator have same resolution but different density. )
The problem is the position of the controls is not same on all the three emulator. As per my understanding if the android:layout_marginLeft and android:layout_marginTop are mentioned in "dip" then this problem should not occur. As the density of the emulator increases the controls get placed more towards the right.
Is it absolutely necessary that i provide layouts for all combination's of screen dimension and density even if the layout is same for all the devices?
Am I missing some important point?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:src="@drawable/bgd" android:scaleType="fitXY">
</ImageView>
<ImageView android:id="@+id/wtButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/button" android:layout_marginLeft="170dip"
android:layout_marginTop="9dip"></ImageView>
<ImageView android:id="@+id/htButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/button2" android:layout_marginLeft="220dip"
android:layout_marginTop="90dip"></ImageView>
</RelativeLayout>
Images:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,您必须在清单文件中添加以下内容,然后它才会采取
根据需要从 ldpi、mdpi、orhdpi 获取资源
Yes you have to ADD the following thing in the manifest file then only it will take the
Resorces from the ldpi,mdpi,orhdpi as per need
首先计算设备高度和宽度
,然后如果您想将视图的 leftpadding 值设置为 180,将 toppadding 值设置为 48,则将其设置为
(320 /1.8 = 1.77)
meterView.setPadding((int) (width/1.8), (int ) (高度/10), 3, 5);
试试这个。
First you calculate device height and width
then if u want set 180 as leftpadding value and 48 as toppadding value for view, then set it as
(320 /1.8 = 1.77)
meterView.setPadding((int) (width/1.8), (int) (height/10), 3, 5);
try this.
问题是随着设备尺寸的增加,图像尺寸会减小。
相应地重新调整图像大小(增加 mdp 和 ldpi 图像的大小)。
如果你想以 Nexus 系列为目标,它总是以 Xhdpi 和 hdpi 为目标,这是一个真正的痛苦。
你也可以参考我这里的回答:
Android:支持多个屏幕
The problem is as the size of the devices increase your image size decrease.
Re-size your images accordingly (increase mdp and ldpi image's size).
If you wnat to target Nexus series, it would always target Xhdpi and hdpi, which is a real pain.
you can also refer to my answer here :
Android: support multiple screens