简体   繁体   English

Android针对不同屏幕尺寸的多种布局

[英]android multiple layouts for different screen sizes

I have a screen that I need to remove some items on smaller screens because they will not fit. 我有一个屏幕,我需要删除一些较小屏幕上的项目,因为它们不适合。 I search for items in the layout to populate with live data in code, such as populating names etc. There are 5 items that need to be populated in my large layout but only 2 in my small layout as three I removed because they won't fit. 我在布局中搜索要用代码中的实时数据填充的项目,例如填充名称等。在我的大布局中需要填充5个项目,而在我的小布局中仅需要填充2个项目,因为我删除了三个项目,因为它们不会适合。 How in my Activity can I tell that I am in "Small mode" and not search the layout for the three id's that I want to skip and not populate? 如何在“活动”中告诉我我处于“小模式”,而不在布局中搜索要跳过但不填充的三个ID?

Do I need to just search for them and catch the errors and ignore or is there a better way? 我是否只需要搜索它们并捕获错误并忽略它们,还是有更好的方法?

Thanks 谢谢

It looks like in this circumstance the widgets will return null when I attempt to find them if the layout chosen doesn't support that widget. 在这种情况下,如果选择的布局不支持该小部件,则当我尝试查找它们时,小部件将返回null。 So I can just detect if its null and if so skip populating the widget. 因此,我可以检测它是否为null,如果是,则跳过填充小部件。

You will want to utilize a combo of the resource directories (high, medium, low) and follow the guidelines on how to support multiple screen sizes from the android documentation. 您将要利用资源目录的组合(高,中,低),并遵循android文档中有关如何支持多种屏幕尺寸的准则。 Also you can get the screen dimensions if you need to anything specific in the code. 如果您需要代码中的特定内容,也可以获取屏幕尺寸。 See these links. 请参阅这些链接。

Get screen dimensions in pixels http://developer.android.com/guide/practices/screens_support.html 获取以像素为单位的屏幕尺寸 http://developer.android.com/guide/practices/screens_support.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM