如何为Samsung S3和Moto X提供不同的尺寸

时间:2016-03-03 15:37:08

标签: android screen-resolution

三星S3 - 720x1280,xhdpi,306ppi

Motorola Moto X - 720x1280,xhdpi,312 ppi

我需要为这些设备提供不同的dimen

我已阅读Supporting Multiple Screens但仍未找到解决方案

看起来像问题,因为Motorola Moto X没有硬件按钮(后面,菜单,主页)

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

您可以将google库PercentRelativeLayout与此库一起使用,您可以按照百分比设置widthheightmargin,这很棒,因为在所有屏幕中它们看起来都很棒同样的,当然不难编码。这里的例子:

<android.support.percent.PercentRelativeLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:app="http://schemas.android.com/apk/res-auto"
         android:layout_width="match_parent"
         android:layout_height="match_parent">
     <ImageView
         app:layout_widthPercent="50%"
         app:layout_heightPercent="50%"
         app:layout_marginTopPercent="25%"
         app:layout_marginLeftPercent="25%"/>
 </android.support.percent.PercentRelativeLayout>

您必须在build.gradle

中添加此行
dependencies {
    compile 'com.android.support:percent:23.2.0'
}

以及Google https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html的官方文档 希望对您的案件有所帮助!