2012-05-15 50 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" />