简体   繁体   English

Android - Galaxy S4和Nexus 5的布局

[英]Android - Layout for both Galaxy S4 and Nexus 5

Is there a specific qualifier I can use in order to make different Layouts specifically for Nexus 5? 我是否可以使用特定的限定符来为Nexus 5制作不同的布局?

I'm using layout-xhdpi for devices such as Galaxy S4 (I've checked on S4 Active which has physical keys) and Note 2, and I don't want to change anything there. 我正在使用layout-xhdpi用于Galaxy S4等设备(我已经检查过具有物理键的S4 Active)和注2,我不想在那里改变任何东西。

EDIT #2 The cause of difference between S4 and Nexus 5, not considering the fact that the Layout is not optimal, is that the effective screen size is not as Galaxy S4 (1920) but smaller - 1776, because of the soft keys. 编辑#2 S4和Nexus 5之间差异的原因,不考虑布局不是最佳的事实,有效屏幕尺寸不是Galaxy S4(1920)而是更小 - 1776,因为软键。

EDIT #3 This is the new layout with only one Relative Layout: (the problem is that android:id="@+id/nextlevel" is located behind android:id="@+id/banner_adview" ) 编辑#3这是只有一个相对布局的新布局:(问题是android:id =“@ + id / nextlevel”位于android:id =“@ + id / banner_adview”后面

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@drawable/bg"
  android:gravity="center_horizontal"
  android:orientation="vertical" >

<TextView
    android:id="@+id/endlevel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_marginBottom="13dp"
    android:background="@drawable/header"
    android:gravity="center"
    android:paddingBottom="1dp"
    android:paddingLeft="15dp"
    android:paddingRight="15dp"
    android:paddingTop="1dp"
    android:textColor="#ecf0f1"
    android:textSize="20sp"
    android:textStyle="normal" >
</TextView>

<TextView
    android:id="@+id/congratulations"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/endlevel"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="7dp"
    android:gravity="center"
    android:text="@string/congratulations"
    android:textColor="#ecf0f1"
    android:textSize="19sp"
    android:textStyle="bold" >
</TextView>

<ImageView
    android:id="@+id/summary"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/congratulations"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="10dp"
    android:layout_marginTop="7dp"
    android:background="@drawable/levelendresultbg" />

<TextView
    android:id="@+id/pointstext"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/congratulations"
    android:layout_marginTop="11dp"
    android:gravity="center"
    android:textColor="#ecf0f1"
    android:textSize="17sp"
    android:textStyle="bold" >
</TextView>

<ImageView
    android:id="@+id/divider"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/pointstext"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="5dp"
    android:src="@drawable/divider" />

<TextView
    android:id="@+id/totalpointstext"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/divider"
    android:layout_marginBottom="4dp"
    android:gravity="center"
    android:textColor="#e1c736"
    android:textSize="17sp"
    android:textStyle="bold" />

<ImageView
    android:id="@+id/award"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/endlevel"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="10dp"
    android:layout_toRightOf="@id/congratulations"
    android:src="@drawable/award" />

<TextView
    android:id="@+id/topborder"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/totalpointstext"
    android:layout_marginTop="13dp"
    android:background="@drawable/border"
    android:gravity="left"
    android:paddingLeft="10dp"
    android:textColor="#ecf0f1"
    android:textSize="17sp"
    android:textStyle="bold" />

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="280dp"
    android:layout_below="@id/topborder"
    android:background="@color/transparent"
    android:cacheColorHint="#00000000"
    android:fadeScrollbars="false" />

<TextView
    android:id="@+id/bottomborder"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@android:id/list"
    android:background="@drawable/border"
    android:gravity="center" />

<ImageButton
    android:id="@+id/nextlevel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/bottomborder"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center"
    android:layout_marginTop="30dp"
    android:background="@drawable/nextlevelbutton"
    android:textSize="20sp" />

<com.google.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/banner_adview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    ads:adSize="BANNER"
    ads:adUnitId="XXXXXXXXXXXX"
    ads:loadAdOnCreate="true"
    android:background="@drawable/adback" />

</RelativeLayout>

Thanks! 谢谢!

If you have a layout with layout-xhdpi or layout-xhdpi, you're probably doing something wrong in the first place. 如果你有一个layout-xhdpi或layout-xhdpi的布局,你可能首先做错了。

The -xhdpi and -xxhdpi qualifiers will affect mostly the drawables, not the layouts (that is unless, you have a background image that takes the entire width or height of a layout). -xhdpi和-xxhdpi限定符将主要影响drawable,而不是布局(除非您有一个背景图像占据布局的整个宽度或高度)。

For layouts, you generally have to use the size qualifiers, not the density qualifiers. 对于布局,通常必须使用大小限定符,而不是密度限定符。 And for the densities, what you must modify are the drawables, not the layouts. 对于密度,你必须修改的是drawables,而不是布局。

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

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