2014-09-05 50 views
0

嗨我的應用在不同的設備上看起來不同。我使用三星Galagy S2作爲我的測試設備,但是當我試圖安裝的應用程序到另一個設備三星Galaxy Note 3佈局在設備上看起來不同

顯示分辨率: 三星Galaxy S2:800×480(HDP) 三星galaxz注3:1920×1080(xxhdp)

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

正如你在第一次看到圖片看起來不錯,但在注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> 
+1

兩幅圖像都是相同的。 – Kishan 2014-09-05 10:11:08

+0

不,我有xxhdp的260x260和hdp的130x130 – user3934048 2014-09-05 10:13:31

+0

我在說你上傳的圖片是一樣的。 – Kishan 2014-09-05 10:15:00

回答

3

您應該使用的LinearLayout來覆蓋你所有的垂直按鈕和設置這個的LinearLayout的layout_height到match_parent.Inside這個LinearLayout中,爲每個按鈕相同的值layout_weight(例如:1)和layout_height到0dp

0

必須管理的高度和寬度與價值觀-V11 dimen.create一個捫,價值觀-V14的基礎上,佈局和校驗值,sw600dp值的佈局和設置高度和寬度。

0

我也有同樣的問題,但我解決了它通過創建3個不同的佈局爲同一活動。

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

你不需要操心分配首選佈局,Android設備選擇最適合他們屏幕的佈局。我的答案似乎是額外的工作,但如果您希望在不同的屏幕尺寸上具有一致的視圖,那麼它是最可取的。閱讀documentation

相關問題