简体   繁体   English

如何设置Galaxy Nexus的布局

[英]How to set up layout to Galaxy Nexus

I'm developing an Android 2.2 application. 我正在开发一个Android 2.2应用程序。

Testing my layout with eclipse graphical layout I have a problem: it doesn't look good on Galaxy Nexus. 使用eclipse图形布局测试我的布局我遇到了一个问题:它在Galaxy Nexus上看起来不太好。

I have four image types: ldpi, mdpi, hdpi and xhdpi. 我有四种图像类型:ldpi,mdpi,hdpi和xhdpi。 A layout and four dimens.xml files (ldpi, mdpi, hdpi and xhdpi). 布局和四个dimens.xml文件(ldpi,mdpi,hdpi和xhdpi)。

If I modify dimens.xml to make it look well with Galaxy Nexus but it won't look well on other device, eg Nexus One (in eclipse graphical layout). 如果我修改dimens.xml以使其与Galaxy Nexus但在其他设备上看起来不太好,例如Nexus One (在eclipse图形布局中)。 So, I think I need something else. 所以,我想我还需要别的东西。

Reading Supporting Multiple Screens I see there is another approach: instead of using normal, large, etc layout, I could use sw<N>dp . 阅读支持多个屏幕我看到还有另一种方法:我可以使用sw<N>dp而不是使用普通,大型等布局。 But this is beginning with Android 3.2, and I need to support Android 2.2. 但这是从Android 3.2开始的,我需要支持Android 2.2。

What do I need to add to make it look well on Galaxy Nexus? 我需要添加什么才能让它在Galaxy Nexus上看起来很好看?

Nexus One : Nexus One
在此输入图像描述



Galaxy nexus : Galaxy nexus

在此输入图像描述

Another approach I often happen to use it to think like web developers. 另一种我经常碰巧使用它像Web开发人员一样思考的方法。 Try to make your layout look good with layout stretched in whatever direction. 尝试使布局看起来很好,布局在任何方向拉伸。 Center the important part and make sure the image behind can be stretched in both directions. 将重要部分居中,确保后面的图像可以向两个方向拉伸。 Then use an imageview for the background and set it to match_parent and scaletype to centerCrop. 然后使用imageview作为背景并将其设置为match_parent,将scaletype设置为centerCrop。 It doesn't work for everything but I'm pretty sure it would work for your sample. 它不适用于所有东西,但我很确定它适用于您的样品。

In your case you could put everything you have right now inside another container (for example a RelativeLayout) then you center it and set the dimensions or make it wrap_content. 在您的情况下,您可以将您现在拥有的所有内容放在另一个容器中(例如RelativeLayout),然后将其居中并设置尺寸或使其成为wrap_content。 The new top container should then match_parent and have the imageview I talked about as a child. 然后,新的顶部容器应该是match_parent并且具有我作为孩子谈论的imageview。

You should keep the different densities for the images, for the layouts you want to use screen sizes eg 对于要使用屏幕尺寸的布局,您应该保持图像的不同密度,例如

layout-large instead of layout-hdpi layout-large而不是layout-hdpi

EDIT 编辑

You want to have a folder layout like this: 你想拥有这样的文件夹布局:

  • res/drawable-ldpi/[your image resources] res / drawable-ldpi / [您的图片资源]
  • res/drawable-mdpi/[your image resources] res / drawable-mdpi / [您的图片资源]
  • res/drawable-hdpi/[your image resources] res / drawable-hdpi / [您的图片资源]
  • res/drawable-xhdpi/[your image resources] res / drawable-xhdpi / [您的图片资源]
  • res/layout/[your layout xml file] res / layout / [你的布局xml文件]
  • res/layout-large/[your layout xml file modified for big screens] res / layout-large / [为大屏幕修改你的布局xml文件]
  • res/layout-small/]your layout xml file modified for small screens] res / layout-small /]为小屏幕修改你的布局xml文件]

See this link for further info: http://developer.android.com/training/basics/supporting-devices/screens.html 有关详细信息,请参阅此链接: http//developer.android.com/training/basics/supporting-devices/screens.html

EDIT2 EDIT2

If you must stick to one layout then you need to edit the values in res/values-large/dimes.xml to affect large screen devices. 如果必须坚持一个布局,则需要编辑res / values-large / dimes.xml中的值以影响大屏幕设备。

If you have and extra large device screen then you'd need to edit res/values-xlarge/dimens.xml and so on for each of the screen sizes. 如果您有超大设备屏幕,那么您需要为每个屏幕尺寸编辑res / values-xlarge / dimens.xml等。

one of my first questions was very similar to this one . 我的第一个问题之一与此问题非常相似。

your problem in short is that you need to have your views placed and resized according to an image that you show on the background . 简而言之,您需要根据您在背景上显示的图像放置视图并调整其大小。 sadly , android doesn't support it without some workarounds . 遗憾的是,没有一些解决方法,android不支持它。

on silverlight&WPF there is a viewBox that does it automatically . 在silverlight和WPF上有一个自动执行的viewBox。 flash has it because it's vector based . flash有它,因为它是基于矢量的。 iphone has it because all of its screens have the same aspect ratio. iPhone有它,因为它的所有屏幕具有相同的宽高比。 but android doesn't have a solution for it yet. 但是android还没有它的解决方案。

i've even asked this same question in google developers day , and what the lecturer told me was that i should use openGL , even though my app was very simple. 我甚至在谷歌开发者日里问了同样的问题,讲师告诉我的是我应该使用openGL,即使我的应用程序非常简单。

for now , what you can do is : 现在,你能做的是:

  1. the easy way : use multiple LinearLayout with weights . 简单的方法:使用多个LinearLayout和权重。 use views inside them with weights too in order to make rules about the positions and sizes. 也可以使用权重内部的视图来制定有关位置和大小的规则。 Lint will tell you that it is bad for performance , but if your views are not moving/resizing at all , it should be ok . Lint会告诉你它对性能有害,但是如果你的视图根本没有移动/调整大小,它应该没问题。

  2. the advanced way: create your own layout , which will know exactly where to put views (and in which size) in relation to what you give to it. 高级方法:创建自己的布局,它将准确地知道放置视图的位置(以及大小)与您提供的内容相关的位置。 i've done it in the past , but i used imageViews instead of buttons (because i had to) . 我在过去做过,但我用的是imageViews而不是按钮(因为我不得不这样做)。

there is also a bug with this approach (also found on solution #1) : on some screens their images didn't fit with the background image. 这种方法也有一个错误(也见于解决方案#1):在某些屏幕上,他们的图像不适合背景图像。 if that's not your case , you can do it too. 如果那不是你的情况,你也可以这样做。

  1. the hardcore way : use openGl . 硬核方式:使用openGl。 it's will be easier to use third party libraries like andEngine or LibGdx . 使用像andEngine或LibGdx这样的第三方库会更容易。

  2. the web-developers way : put it all in a website , show it, handle touches using an interface with android . 网络开发者的方式:把它全部放在网站上,展示它,使用android界面处理触摸。

  3. the no-buttons way: if you don't want to use the buttons , you can use simple math in order to know where the user has pressed , and not use any of the above solutions . 无按钮方式:如果您不想使用按钮,可以使用简单的数学运算来了解用户按下的位置,而不使用上述任何解决方案。

btw , if you stretch the image like what i see , it won't keep its aspect ratio . 顺便说一句,如果像我看到的那样拉伸图像,它将无法保持其宽高比。 you need to handle it too . 你也需要处理它。 using openGl can help you with that. 使用openGl可以帮助你。

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

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