如何为 Samsung S3 和 Moto X 提供不同的尺寸
How to provide different dimensions for Samsung S3 and Moto X
三星 S3 - 720x1280,xhdpi,306ppi
摩托罗拉 Moto X - 720x1280,xhdpi,312 ppi
我需要为这些设备提供不同的dimen
。
我已阅读Supporting Multiple Screens但仍未找到解决方案
看起来有问题,因为 Motorola Moto X
没有硬件按钮(返回、菜单、主页)
我怎样才能做到这一点?
您可以将 google 库 PercentRelativeLayout
与此库一起使用 您可以按百分比设置 width
、height
和 margin
的观看次数,这很棒因为在所有屏幕上它们看起来都一样,当然编写代码并不难。这里的例子:
<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 的官方文档
希望这对您的案例有所帮助!
三星 S3 - 720x1280,xhdpi,306ppi
摩托罗拉 Moto X - 720x1280,xhdpi,312 ppi
我需要为这些设备提供不同的dimen
。
我已阅读Supporting Multiple Screens但仍未找到解决方案
看起来有问题,因为 Motorola Moto X
没有硬件按钮(返回、菜单、主页)
我怎样才能做到这一点?
您可以将 google 库 PercentRelativeLayout
与此库一起使用 您可以按百分比设置 width
、height
和 margin
的观看次数,这很棒因为在所有屏幕上它们看起来都一样,当然编写代码并不难。这里的例子:
<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 的官方文档 希望这对您的案例有所帮助!