如何使用按钮文本两种不同的字体大小在Android的? [英] How to use two different font sizes for button text in Android?

查看:646
本文介绍了如何使用按钮文本两种不同的字体大小在Android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能落实的ImageButton或按钮,其中包含2 TextView中分别使用不同的字体大小按钮背景?我不能使用静态图片作为背景,我需要或者达到这个使用XML或编程。

How could I implement a button background for ImageButton or Button which contains 2 textview each using different font sizes ? I cant use static images as background and I need to achieve this either using xml or programmatically.

这是一个数字键盘和它所携带的数字值和一组字母的每一个都使用不同的字体大小,需要设置为按钮文本

This is a numeric keypad and it carries a numeric value and a set of alphabets each of which uses different font sizes and needs to be set as button text.

下面是一些建议,弹出在我的大脑,但似乎有一定的局限性,因为我想重用的UI组件,避免code重复。

Here are some of the suggestions that pop-up on my brain but seems to have limitations since I want to reuse the UI component and avoid code repetition.


  1. 创建一个包含2文本框的布局XML,并设置为按钮背景。但我怎么能得到这些TextView中字段的参考设定对他们的价值在MyActivity.java?

  1. Create a layout xml containing 2 textfields and set that as background on the button. But how can I get a reference of these textview fields to set the value on them in the MyActivity.java?

使用一个layeredlist?还是textviews的同样的问题,参考

Use a layeredlist ? still same problem reference of textviews

或者创建自定义视图和膨胀在步骤1中提到的布局该解决方案可以解决我的问题。

Or create a custom view and inflate layout mentioned in step 1. This solution resolves my problem.

有没有其他的解决方案存在此UI要求?

Does any other solution exist for this UI requirement?

感谢。

推荐答案

希望这会有所帮助。这一关课程是不是唯一的解决方案,但它是一个pretty简单。在XML而非按钮添加XML的部分。

Hopefully this will help. This off course is not the only solution but it is a pretty simple one. Add the xml part in your xml instead of the button.

XML

<LinearLayout
    android:id="@+id/button_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp" 
        android:text="5"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="12sp" 
        android:text="ABC"/>

</LinearLayout>

code

    LinearLayout button= (LinearLayout)findViewById(R.id.button_layout);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO DO whatever you want to do here

        }
    });

这篇关于如何使用按钮文本两种不同的字体大小在Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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