-1

我有一個RelativeLayout風格爲ButtonBar和包含在HorizontalScrollView,這種佈局是ssigned到一個固定的高度,以控制,但使它看起來巨頭在小屏幕設備,如何在Relativelayout中製作靈活大小的按鈕?

爲前,中10'設備:

enter image description here

而在一個3.7'設備:

enter image description here

這是我的XML代碼:

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tool" 
    android:id="@+id/horizontalScrollView1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="true" > 
    <RelativeLayout 
     android:id= "@+id/buttobbar" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:gravity="top" 
     style="@android:style/ButtonBar" 
     android:background="@drawable/released" > 

     <Button 
      android:id="@+id/Main" 
      android:layout_width="120dp" 
      android:layout_height="60dp" 
      android:background="@android:color/transparent" 
      android:textColor="@android:color/white" 
      android:textStyle="bold" 
      android:text="@string/main"/> 

     <View 
      android:id="@+id/separator" 
      android:layout_height="fill_parent" 
      android:layout_toRightOf="@+id/Main" 
      android:layout_width="1px" 
      android:background="@drawable/separators"/> 

     <Button 
      android:id="@+id/HomeView" 
      android:layout_width="120dp" 
      android:layout_height="60dp" 
      android:background="@android:color/transparent" 
      android:textColor="@android:color/white" 
      android:textStyle="bold" 
      android:layout_toRightOf="@+id/Main" 
      android:text="@string/homeview" /> 

     <View 
      android:id="@+id/separator" 
      android:layout_height="fill_parent" 
      android:layout_toRightOf="@+id/HomeView" 
      android:layout_width="1px" 
      android:background="@drawable/separators"/> 

      . 
      . 
      . <!-- after 7 other buttons separated with views --!> 
    </RelativeLayout> 
    </HorizontalScrollView> 

回答

0

增加重量將是一個最好的選擇: 試試這個:

android:weightSum="1" 

和劃分這個重量總和如下:

android:layout_weight=0.5 
1

在相對佈局的地方走線佈局和u不必須給layout_width的絕對值剛剛使用Android:layout_weight並給予重於所有按鈕 從這個它都將自動在屏幕上的任何調整將是 我認爲這將幫助ü

0

分配權重佈局(線性佈局)僅通過寫下面的代碼:

android:weightSum="1"(can vary,according to your requirement) 

和劃分這個重量總和的butons如下:

android:layout_weight=0.5

+0

和寬度和高度? – MRefaat

+0

android:layout_width =「fill_parent」 android:layout_height =「wrap_content」 – Pihu

+0

此寬度和高度要設置爲線性佈局 – Pihu

相關問題