2011-04-21 58 views
1

嗨全部 我必须使用线性布局与所有分辨率类型的设备,如480x800,480x854,320x480。 我使用x,y位置将元素放置在线性布局中,同时为320x480进行设计。我必须重新设计其他分辨率设备,因此需要更多时间。请以线性布局给出所有分辨率的常用方法。提前致谢。如何为所有设备分辨率设计

回答

2

请勿为特定分辨率设计。使用属性的值,layout_widthlayout_height值的组合wrap_contentmatch_parent以根据屏幕大小获得不同的比例宽度,而不是硬编码像素值。

例如,假设您要添加的四个按钮一排,每占用宽度相等,在屏幕的上方,由〜5个像素左顶偏:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="5dp" 
    android:gravity="top" 
    android:orientation="horizontal" 
    > 
    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"  
     android:text="Button 1" 
     /> 
    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"  
     android:text="Button 2" 
     /> 
    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"  
     android:text="Button 3" 
     /> 
    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"  
     android:text="Button 4" 
     /> 
</LinearLayout> 

这将为任何屏幕密度提供可靠的结果,而且您​​无需担心某个像素值。用于填充的dp(与设备无关的像素)的使用也会根据密度而略有变化,因此无论分辨率如何,它都会保持一致的物理尺寸。

通读关于LinearLayouts,FrameLayouts和RelativeLayouts的示例Android Developers site。你会很好地感受每个人的优点和缺点。

0

非常好的答案......我相信很多个人和企业都认为Android是一个“设备”,而不清楚Android是否是一个“操作系统”。为了正确显示运行Android OS的所有设备的图像,必须选择支持多种设备,并根据Android OS进行开发,而不是运行Android OS的特定设备。我之前遇到过这个问题,我的老板(当时)说:“你的测试设备需要什么尺寸的图像?我说”只是让我的图像!我被迫使用320x480图像(根据测试设备),当区域经理在他的ThinkPad(和其他4个设备)上看到演示产品时,我终止了我的位置,因为我的主管认为Android是设备而不是操作系统...和公司的Android应用尚未完成。 我的意见持有决议‘是对某一设备或设备类型“支持多发设备是开发根据通用的Android OS开发’。

+0

感谢我有同样的问题,解决了支持一些你有没有得到职位? – 2012-02-11 12:24:36

+0

我在正确的地方,在正确的时间说话,我获得了这个职位,但最终在发展中,你必须知道该做什么,去哪里或者去问谁...像这样**这里很棒的人在Stackoverflow **网络。 – KaSiris 2012-02-11 18:39:33