对于目标定位范围广泛的设备和屏幕尺寸的最佳实践 [英] Best practices for targetting a wide range of devices and screen sizes

查看:146
本文介绍了对于目标定位范围广泛的设备和屏幕尺寸的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如你今天所知道Android是众多版本众多建设者,许多的屏幕尺寸,...

As you know android today is many versions many constructors, many screen sizes,...

这是相当困难的开发商今天编写目标设备的重要组成部分节目。

it's quite difficult for developers today to write programs that targets a big part of devices.

什么是开发者必须知晓做法呢?

What would be THE developer must-know practices for this ?

  • 提示流动布局。
  • 在标准制定的任何Android版本。
  • ...

任何其他的想法?

推荐答案

首先,你应该通过阅读官方开始支持多个屏幕最佳实践的。有很多很好的提示,在那里,以及你所需要的是寻找在兼容性方面的总体思路。

For Layouts

First, you should start off by reading the official Supporting Multiple Screens Best Practices. There are a lot of good tips there, as well as a general idea on what you need to be looking for in terms of compatibility.

有一件事情我认为是非常有帮助的,这似乎很明显,是真正考验你的布局不同大小的仿真器。请问你的布局看,当扩展到1024×768(即使没有设备都会有这样的资源)?怎么样,当它的超纤巧和方?看到如何布局绵延/合同将帮助你调整它,以便更好地适用于所有的屏幕。

One thing I've found to be very helpful, which seems quite obvious, is to actually test your layout in various sized emulators. How does your layout look when expanded to 1024x768 (even though no device will have such a res)? How about when it's super tiny and square? Seeing how your layout stretches/contracts will help you tweak it to better fit all screens.

在布局中,的android:layout_weight 是一个功能强大,但在记载的属性。使用它,您可以创建布局,其中元件的尺寸用百分比给对方。

In layouts, android:layout_weight is a powerful, but under-documented attribute. Using it, you can create layouts where components are sized in percentages to each other.

例如:

<LinearLayout android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <EditText android:layout_weight="80" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <Button android:layout_weight="20"
        android:text="Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content />
</LinearLayout>

在这种布局中,&LT;的EditText /&GT; 将占据80%的可用宽度,而&LT;按钮/&GT ; 将占用可用宽度的20%。显然,这应该小心使用,使所有项目仍可以是即使是小可用。

In this layout, the <EditText/> will take up 80% of the available width, while the <Button/> will take up 20% of the available width. Obviously, this should be used carefully so that all items can still be usable even if they are small.

另一个有用的布局做法是捆绑了布局的常见位为独立的文件,包括他们使用&LT;包括布局=@布局/ smaller_section/&GT; 。这样一来,就可以在布局的其他部分洗牌(比如说,风景),而不必保留布局整个并行版本。

Another helpful layout practice is to bundle up common bits of your layout into separate files and include them using <include layout="@layout/smaller_section" />. That way, you can shuffle around other parts of the layout (say, for landscape), without having to keep entire parallel versions of the layout.

这篇关于对于目标定位范围广泛的设备和屏幕尺寸的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆