2015-04-03 19 views
0

我試過這段代碼,但是這些按鈕上的文字在我的手機中混淆了;雖然它在Nexus 5仿真器中沒有問題....!我怎樣才能把這些4個按鈕一行動態,使他們可以看看在任何屏幕尺寸相同...即使應用在任何屏幕尺寸上運行,如何將這四個按鈕設置爲一行?

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp" 
    android:weightSum="8" > 

    <Button 
     android:id="@+id/bback" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:text="Back" /> 

    <Button 
     android:id="@+id/bforward" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:text="Forward" /> 

    <Button 
     android:id="@+id/brefresh" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:text="Refresh" /> 

    <Button 
     android:id="@+id/bclear" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:text="Clear History" /> 
</LinearLayout> 
+0

使用width作爲wrap_content可能會解決您的問題。那麼你將不得不去除權重。 – 2015-04-03 08:34:06

+0

但隨後按鈕尺寸會變得不同...... :( – Saurabh 2015-04-03 08:39:22

+0

是否要在任何屏幕尺寸下保持按鈕尺寸相同 – 2015-04-03 08:47:04

回答

1

設置android:layout_width0dp而不是fill_parent所有按鈕。

0

試試這個,它會保持按鈕的大小在任何設備一樣,也流傳按鈕與任何設備上等距離,

 <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" > 

      <LinearLayout 
       android:id="@+id/1" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:orientation="vertical" > 

       <Button 
        android:id="@+id/bback" 
        android:layout_width="40dp" 
        android:layout_height="40dp" 
        android:text="Back" 
        android:layout_gravity="center" /> 
      </LinearLayout> 

      //same as layout 2,3,4 and respective button with in it 


     </LinearLayout> 
0

EDITTEED 請嘗試使用此:

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

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="5" 
     android:orientation="vertical" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     > 

     <Button 
      android:id="@+id/bback" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:text="Back" /> 

     <Button 
      android:id="@+id/bforward" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:text="Forward" /> 

     <Button 
      android:id="@+id/brefresh" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:text="Refresh" /> 

     <Button 
      android:id="@+id/bclear" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:text="Clear History" /> 
    </LinearLayout> 
</LinearLayout> 
+0

height = 0dp?!它顯示錯誤 – Saurabh 2015-04-03 10:36:44

+0

我做了編輯pls ..檢查這個..我也檢查了th是.. HappY編碼.. – 2015-04-03 10:51:33

相關問題