2013-07-23 19 views
1

我目前正在學習Android開發,遵循一本書並使用Android Studio進行測試創建和Nexus 4設備。我一直在使用佈局預覽器來測試我的佈局,看它是否好用。Android Studio:在佈局預覽中顯示的距離在設備上顯示爲較大

下面是該佈局的屏幕截圖以及它在Android Studio預覽器中的顯示方式。對不起,大尺寸。

enter image description here

這裏是我的Nexus 4設備拍攝,以顯示不同的屏幕截圖。

enter image description here

正如你可以看到的EditText字段表示作爲在預覽行,但脫節的設備上。我比較了2張圖片,其餘的元素都按原樣放置,除了EditTexts。佈局使用2個嵌套的LinearLayout,一個向左右一個。

下面是我的一個EditText在XML中的定義。所有其他人都是不同ID的副本。

<EditText android:id="@+id/editTextColonies" 
      android:inputType="number" 
      android:ems="12" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="12dp"/> 

我想知道這是由我的代碼,我的設備還是簡單的Android Studio造成的。 預先感謝您的解決方案。

回答

2

如果可以,切換到RelativeLayout,然後可以定義android:layout_toRightOf和android:layout_below XML標記。我不推薦使用GUI來放置RelativeLayout對象,因爲它很煩人。將它與XML放在一起更容易。

+1

謝謝,我適應於RelativeLayout的,並對齊設置了這種方式基線和父權。 – Linkandzelda

+0

沒有問題,用upvote或兩個幫助你;) – Steven

0

在EditTexts旁邊放置按鈕行。每行應該是一個LinearLayout或RelativeLayout,並且您應該爲每個行設置android:height =「wrap_content」。把你的按鈕edittext對放入其中。

<LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="bottom" > 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/button_name_colonists" 
      android:id="@+id/colonistsButton"/> 

     <EditText android:id="@+id/editTextColonists" 
       android:inputType="number" 
       android:ems="12" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="12dp"/> 

    </LinearLayout> 

</LinearLayout> 

的東西來看待,使用重新佈局,如常用重複行是this link by Google about include.

+0

非常感謝你,但最終我決定去與RelativeLayout。 – Linkandzelda

相關問題