2012-05-15 48 views
2

我在按鈕中的文本的大小有問題。我有我使用weightSum的佈局,我的按鈕寬度是匹配的父項,高度是30%。一切工作正常,但是當我在模擬器上更改屏幕大小時,我的文本仍然很小。我怎樣才能改變大小的文字取決於屏幕的大小? 這是XML:按鈕和文本的大小

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="100" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     android:layout_weight="30" /> 

</LinearLayout> 

有什麼辦法可以全自動做到這一點?

回答

3

使用SP爲單位TEXTSIZE按鈕

<Button 
android:id="@+id/button1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Button" 
android:textSize="20sp" 
android:layout_weight="30" /> 

的。如果這不能解決您的問題,創建文件夾一樣

1)佈局 2)佈局小 3)佈局,大 4)layout-xlarge

按照Nikhil的建議,但隨着這個做考慮this

同文件夾建議上面可以爲每個畫面類型

1)的值來創建不同的值的文件夾2)的值小3)值-大...

創建xml文件名爲dimens.xml在它們中的每並用如下

<Button 
android:id="@+id/button1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Button" 
android:textSize="@dimen/small_font" 
android:layout_weight="30" /> 

捫資源的基準指定按鈕的TEXTSIZE這將根據屏幕尺寸

希望這將是有用噸設置字體大小你

1

如果您添加到XML的按鈕:

<Button 
    android:id="@+id/button1" 
    android:text="click me" 
    android:textSize="22dp" /> 

這應該做的伎倆。

如果要動態地改變文字大小,你應該得到的屏幕尺寸,然後設置TEXTSIZE與button.setTextSize(size);

-2
<Button 
    android:id="@+id/button1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:textSize="22dp" 
    android:layout_weight="30" />