按钮和文本大小 [英] Button and size of text

查看:116
本文介绍了按钮和文本大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在按钮上的文字大小的问题。我有布局,我使用weightSum和我的按钮的宽度是匹配父母HIGHT为30%。一切工作正常,但是当我改变屏幕尺寸上的模拟器我的文字仍然很小。如何我可以改变文字大小取决于屏幕大小?
这是XML:

I have a problem with size of text in button. I have layout where I use weightSum and my button width is match parent and hight is 30%. Everything works fine but when I change size of screen on emulator my text is still small. How I can change size text depend on size of screen? This is 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>

有什么办法做到这一点全自动?

There is any way to do this automaticly?

推荐答案

使用SP为单位TEXTSIZE按钮

Use sp as unit for textsize of button

<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" />

如果这不能解决您的问题,创建一个类似文件夹

If this does not solve your problem, create folder like

1)布局
2)布局小
3)布局大
4)布局XLARGE

1) layout 2) layout-small 3) layout-large 4) layout-xlarge

由尼基尔但随着这所建议不要考虑这个

as suggested by Nikhil but along with this do consider this

同建议你上面可以为每个屏幕类型不同值的文件夹的文件夹

Same as folders suggested above you can create different values folder for each screen type

1)值2)值小3)值,大...

1) values 2) values-small 3) values-large ...

在他们每个人创建一个名为dimens.xml XML文件,并与扪资源如下

create xml file called dimens.xml in each of them and specify the textSize of your button with the reference of dimen resources as below

<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" />

这将根据屏幕大小设置字体大小

This will set font size according to the screen size

希望这将是对你有用

这篇关于按钮和文本大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆