2011-07-20 9 views
3

長いテキストを割り当てるときにボタンのサイズ変更を防ぐことができるかどうかは疑問でした。テキストが長すぎるとボタンのサイズが変更されないようにしますか?

レイアウトに4行2列を配置したいのですが、1つのテキストを変更すると、自動的に他のものを縮小してサイズを変更することはありません。

私は体重、体重合計、重力を試しましたが、私はこれらの属性の理解の欠如を認めなければなりません!

これは、これまでのところ、私のXMLです:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/linearLayout1" 
    android:background="@drawable/backgroundrepeat" 
    android:orientation="vertical" 
    android:weightSum="2"> 
    <ScrollView android:id="@+id/scrollView1" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:layout_weight="2"> 
     <TextView android:id="@+id/textView1" 
      android:layout_width="match_parent" 
      android:text="TextView" 
      android:layout_height="wrap_content"> 
     </TextView> 
    </ScrollView> 
    <LinearLayout android:layout_height="wrap_content" 
     android:id="@+id/linearLayout3" 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:weightSum="4.0" 
     android:gravity="left"> 
     <Button android:text="Button" 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:layout_weight="1.0"> 
     </Button> 
     <Button android:text="Button" 
      android:gravity="center" 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:layout_weight="1.0"> 
     </Button> 
     <Button android:text="Button" 
      android:id="@+id/button3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:layout_weight="1.0"> 
     </Button> 
     <Button android:id="@+id/button4" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="Button" android:layout_weight="1.0"> 
     </Button> 
    </LinearLayout> 
    <LinearLayout android:layout_height="wrap_content" 
     android:id="@+id/linearLayout3" 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:weightSum="4.0" 
     android:gravity="left"> 
     <Button android:text="Button" 
      android:id="@+id/button5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:layout_weight="1.0"> 
     </Button> 
     <Button android:text="Button" 
      android:gravity="center" 
      android:id="@+id/button6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:layout_weight="1.0"> 
     </Button> 
     <Button android:text="Button" 
      android:id="@+id/button7" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:layout_weight="1.0"> 
     </Button> 
     <Button android:id="@+id/button8" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="Button" android:layout_weight="1.0"> 
     </Button> 
    </LinearLayout>   
</LinearLayout> 
+1

あなたは両方のボタンの幅を "ラップコンテンツ"とし、その結果起こっている固定値の幅に変更し、省略記号も設定しました。 – Pravy

答えて

10

あなたのボタンに追加するには、テキスト文字列

にしたい-any適切な計算されたサイズ、これは文字を制限し、追加されますが、「...」属性
<Button 
    android:id="@+id/yourButtonID" 
    android:layout_width="70dp" 
    android:layout_height="60dp" 
    android:textSize="12sp" 
    android:scrollHorizontally="true" 
    android:lines="1" 
    android:ellipsize="end"/> 
関連する問題