简体   繁体   中英

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?

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.

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.

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" )

<?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.

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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