簡體   English   中英

設備上的布局看起來有所不同

[英]Layout looks different on devices

嗨,我的應用在不同的設備上看起來有所不同。 我使用Samsung Galagy S2作為測試設備,但是當我嘗試將應用程序安裝到另一台設備Samsung Galaxy Note 3上時。

顯示分辨率:Samsung galaxy S2:800x480(hdp)Samsung galaxz Note 3:1920x1080(xxhdp)

我的應用程序看起來:三星Galaxy S2像三星Galaxy Note 3像

如您在第一張圖片中所見,它看起來不錯,但是在Note 3上,應用程序底部有很多空白空間。 我使用的所有圖像也是xxhdp和hdp。 問題出在按鈕之間。 我在dp中進行了設置,因此我認為在每台設備中它的外觀都將在手機中顯示。 但是在星系S2和星系注3上,它看起來是相同的。

這是我的布局。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearLayoutHA"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/background" >

    <RelativeLayout
        android:id="@+id/relativeLayoutHA"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/infoButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minHeight="0dp"
            android:minWidth="0dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="@drawable/info"
            />

        <Button
            android:id="@+id/facebookButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minHeight="0dp"
            android:minWidth="0dp"
            android:layout_alignParentTop="true"
            android:layout_toLeftOf="@+id/infoButton"
            android:layout_marginRight="5dp"
            android:background="@drawable/facebook"
             />

         <Button
            android:id="@+id/emailButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minHeight="0dp"
            android:minWidth="0dp"
            android:layout_alignParentTop="true"
            android:layout_toLeftOf="@+id/facebookButton"
            android:layout_marginRight="5dp"
            android:background="@drawable/email"
             />

    </RelativeLayout>

    <Button
        android:id="@+id/animal"
        android:layout_width="200dp"
        android:layout_height="55dp"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:background="@drawable/shape_button"
        android:drawableLeft="@drawable/animal_pic"
        android:text="Animals" />

    <Button
        android:id="@+id/insect"
        android:layout_width="200dp"
        android:layout_height="55dp"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:background="@drawable/shape_button"
        android:drawableLeft="@drawable/insect"
        android:text="Insects" />

    <Button
        android:id="@+id/nature"
        android:layout_width="200dp"
        android:layout_height="55dp"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:background="@drawable/shape_button"
        android:drawableLeft="@drawable/nature"
        android:text="Nature" />

    <Button
        android:id="@+id/people"
        android:layout_width="200dp"
        android:layout_height="55dp"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:background="@drawable/shape_button"
        android:drawableLeft="@drawable/people"
        android:text="People" />

    <Button
        android:id="@+id/gun"
        android:layout_width="200dp"
        android:layout_height="55dp"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:background="@drawable/shape_button"
        android:drawableLeft="@drawable/gun"
        android:text="Guns" />



</LinearLayout>

您應使用LinearLayout覆蓋所有垂直按鈕,並將此LinearLayout的layout_height設置為match_parent。在此LinearLayout內,將每個按鈕的layout_weight設置為相同的值(例如:1),並將layout_height設置為0dp

您必須使用dimen管理高度和寬度。為values-v11,values-v14,values-sw600dp值布局創建尺寸,並根據布局和檢查設置高度和寬度。

我也遇到了同樣的問題,但是我通過為同一活動創建3種不同的布局來解決了這個問題。

  1. layout_large(用於xhdp布局)
  2. layout_xlarge(用於xxhdp布局)
  3. 布局(用於xhdp布局)

您無需為分配首選布局而煩惱,Android設備會選擇最適合其屏幕的布局。 我的回答似乎是多余的工作,但如果您希望在不同的屏幕尺寸上獲得一致的視圖,則它是最可取的。 閱讀文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM