2014-10-29 127 views
0

如何优化我的应用程序以支持多种屏幕尺寸? 我正在研究一个项目,其中大部分图形都是XML可绘制的,没有定义的大小。 我曾尝试与值文件夹中的维度(ldpi,mpdi,etcetc),但那并没有真正做这项工作。我遇到了一些屏幕出现的问题,所以我尝试了为每种屏幕尺寸创建不同的布局,但同样的事情发生,应用程序在4.3 ... 5“”设备上看起来不错,但是当我启动3.7模拟器时,应用程序看起来很糟糕,有些物品在屏幕外/被其他物品覆盖。 我使用相对布局,我没有看到代码的需要,但如果需要我会发布。 我的问题是:什么是优化应用程序以支持多种屏幕尺寸的最佳方式?支持多种屏幕尺寸Android

回答

1

我觉得你的出发点应该是通过这个页面由谷歌一下:https://developer.android.com/guide/practices/screens_support.html

而且,这里有一些指针:

  • 自由使用“WRAP_CONTENT”和“match_parent”高度和宽度布局属性。避免,设定明确的尺寸在可能的情况
  • 当你需要设定明确的大小,考虑使用不同的屏幕上dimen.xml或考虑设置值语法亲
  • 确保您可绘制,别有不同的清晰图片'忘记可绘制的nodpi文件夹
-1

您应该为每种屏幕尺寸(小,正常,大和X大)创建4个文件夹。 右键单击编辑器中的res文件夹并选择New - > AndroidResourceDirectory从Available qualifier中选择大小并创建每种大小的文件夹。 祝你好运

+0

此方法已被弃用,因为它与屏幕尺寸和新密度没有关联。 2014年的手机将是x-large,与2011平板电脑一样。 – 2014-10-29 18:21:01

0

我发现的最好的方法是在用XML定义布局时非常周到。在大多数情况下,你会发现你可以定义你的布局,以便它们能够在设备之间适当地扩展,直到你达到真正的高端。

拿这个布局,例如:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/MainLinView1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" > 

<LinearLayout 
    android:id="@+id/KeywordItemViewMain" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="@dimen/defViewMargin" 
    android:layout_marginRight="@dimen/defViewMargin" 
    android:layout_marginTop="@dimen/defViewMarginTopBottom" 
    android:layout_marginBottom="@dimen/defViewMarginTopBottom" 
    android:background="@drawable/rounded_corners_background" 
    android:gravity="center" 
    android:orientation="horizontal" 
    android:padding="@dimen/defViewPadding" > 

    <TextView 
     android:id="@+id/rowKeywordTitle" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:padding="5dp" 
     android:text="@string/keywordrow_name" 
     android:textSize="15sp" 
     android:textStyle="bold" /> 

</LinearLayout> 

<LinearLayout 
    android:id="@+id/icons" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignRight="@+id/KeywordItemViewMain" 
    android:layout_centerVertical="true" > 

    <ImageView 
     android:id="@+id/acknowledgedIcon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/handled" 
     android:padding="5dp" 
     android:src="@drawable/acknowledge_item_icon" /> 
</LinearLayout> 

填充母&总结的内容将是你最好的朋友。

我只使用小,正常,大和X大的文件夹时,我真的需要指定不同设计的电话之间的布局或真正的高/低端屏幕尺寸,因为我觉得它令人讨厌做4/5编辑每次我想对布局进行微小的修改。