2016-04-05 17 views
0

Screenshot of first image Screenshot of other phone我有一個的LinearLayout,RelativeLayout的,的LinearLayout和it.This一個ImageView的基本上是我的應用程序的登陸頁面,使用DP的inspite我的輸出是不一樣在所有設備上。有兩個不同手機的屏幕截圖。在此先感謝Android的佈局跨設備並不一致,而不是使用DP

<LinearLayout 
     android:id="@+id/lb_LinearLayout" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <RelativeLayout 
     android:id="@+id/lb_Relative_HomeScreen" 
     android:layout_width="match_parent" 
     android:layout_height="450dp"> 
      <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="350dp"> 
      `` <ImageView 
       android:id="@+id/lb_Background_Image" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="fitXY" /> 
      </LinearLayout> 
      <TextView 
       android:id="@+id/lb_Welcome" 
       android:text="@string/welcome" 
       android:gravity="start" 
       style="@style/Heading2.yellow" 
       android:layout_width="match_parent" 
       android:layout_height="30dp" 
       android:layout_gravity="start|center_vertical" 
       android:layout_above="@+id/lb_Descrption" 
       android:layout_marginLeft="20dp" 
       /> 
... 
</RelativeLayout> 
</LinearLayout> 
+1

屏幕截圖在哪裏? –

+0

抱歉,忘了補充圖片...現在加入.. – user3275601

+0

我認爲你應該使用'Scroll View'來讓它適用於所有設備。 –

回答

2

您需要爲主要的屏幕密度桶和屏幕尺寸創建不同的佈局文件。通過這種方式,您可以對佈局進行微調,使其在多個顯示器中保持一致。

您可以輕鬆地從預覽窗口中的特定存儲分區創建一個新的佈局:

  • 在左上角點擊這個圖標enter image description here。然後選Create Other...
  • 將出現一個彈出窗口,然後從Available Qualifierssize項目中選擇Density不同屏幕尺寸的不同密度桶。
  • 在您選擇了想要的項目後,按>>鍵,您可以選擇適合您想要創建新佈局文件的桶。
  • 在此之後,您按下ok鍵,android studio會爲您創建一份當前佈局的副本並將其放置在適當的文件夾中,您需要做的就是編輯它,使其看起來像您想要的樣子看具體的佈局。
0

你應該使用滾動型是這樣的:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content"> 
<LinearLayout 
    android:id="@+id/lb_LinearLayout" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <RelativeLayout 
     android:id="@+id/lb_Relative_HomeScreen" 
     android:layout_width="match_parent" 
     android:layout_height="450dp"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="350dp"> 
      `` <ImageView 
      android:id="@+id/lb_Background_Image" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scaleType="fitXY" /> 
     </LinearLayout> 
     <TextView 
      android:id="@+id/lb_Welcome" 
      android:text="@string/welcome" 
      android:gravity="start" 
      style="@style/Heading2.yellow" 
      android:layout_width="match_parent" 
      android:layout_height="30dp" 
      android:layout_gravity="start|center_vertical" 
      android:layout_above="@+id/lb_Descrption" 
      android:layout_marginLeft="20dp" 
      /> 
     ... 
    </RelativeLayout> 
</LinearLayout> 

而且能與所有設備兼容,嘗試使用「WRAP_CONTENT」或「match_parent」的高度和寬度。如果圖像讓你在代碼中聲明DP,那麼請通過這個鏈接: https://developer.android.com/guide/practices/screens_support.html

相關問題