冰淇淋sandawich动态变化TEXTSIZE [英] dynamic textsize change in ice cream sandawich

查看:213
本文介绍了冰淇淋sandawich动态变化TEXTSIZE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按钮被点击时,改变文字大小。
XML:

I am trying to change text size when button is clicked. xml :

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:text="hello_world"

   android:textSize="30sp"
   android:layout_margin=""/>

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="72dp"
    android:layout_toLeftOf="@+id/textView1"
    android:text="Button1" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/button1"
    android:layout_toRightOf="@+id/textView1"
    android:text="Button2" />

这是我的code:

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    txtmain=(TextView)findViewById(R.id.textView1);
    txtmain.setTextSize(TypedValue.COMPLEX_UNIT_SP ,30);

    //txtmain.setTextSize(TypedValue.COMPLEX_UNIT_SP ,30);

    txtmain.setTextAppearance(getApplicationContext(), 12);
    btn1=(Button)findViewById(R.id.button1);
    btn2=(Button)findViewById(R.id.button2);
    txtmain.setBackgroundColor(Color.YELLOW);
    btn1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            txtmain=(TextView)findViewById(R.id.textView1);


            txtmain.setTextSize(TypedValue.COMPLEX_UNIT_SP ,30);
            System.out.println("txtmain get height:"+txtmain.getHeight());
            //Toast.makeText(getApplicationContext(),"txtmain get 
            //height:"+txtmain.getHeight() , Toast.LENGTH_LONG).show();
        }
    });

    btn2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            txtmain=(TextView)findViewById(R.id.textView1);

            txtmain.setTextSize(TypedValue.COMPLEX_UNIT_SP ,80);
            System.out.println("txtmain get height:"+txtmain.getHeight());
            //Toast.makeText(getApplicationContext(),"txtmain get 
             //height:"+txtmain.getHeight() , Toast.LENGTH_LONG).show();
        }
    });

当我点击按钮1,它给出正确的输出,但是当我点击一下按钮1输出更改后按钮2。

When I click button 1, it gives proper output but when I click button 2 after clicking button1 output changes.

下面是我的输出:


推荐答案

这似乎是非常相似的称为ICS上一个已知的问题,看到的 HTTPS://$c$c.google.com/p/android/issues/detail ID = 22493 和<一个HREF =HTTPS://$c$c.google.com/p/android/issues/detail ID = 17343?相对=nofollow> HTTPS://$c$c.google.com/p/android /问题/细节?ID = 17343 。其次这些表明,一个解决方法是将一个\\ n添加到文本视图中的文本。读了这些网页以及它们链接到可帮助解决此问题给你。

This would appear to be quite similar to known a known issue on ICS, see https://code.google.com/p/android/issues/detail?id=22493 and https://code.google.com/p/android/issues/detail?id=17343. The second of these suggests that a workaround is to add a "\n" to the text in the text view. Reading up those pages and those they link to may help resolve the issue for you.

这篇关于冰淇淋sandawich动态变化TEXTSIZE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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