2013-05-08 3 views
0

Я пытаюсь изменить размер текста при нажатии кнопки. XML:динамическое изменение текста в мороженом sandawich

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

Это мой код:

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, она дает правильный выход, но при нажатии на кнопку 2 после нажатия Button1 выхода изменения.

Вот мой результат:

enter image description here

enter image description here enter image description here

+0

Не могли бы вы разместить раскладку xml, пожалуйста? Это может дать некоторое представление о том, что происходит. Благодаря! –

+0

@NeilTownsend: я помещаю xml-файл. – Hemant

+0

@AlexanderW, я редактирую мой код посмотрите пожалуйста. – Hemant

ответ

1

Это похоже на известную известную проблему на ICS, см. https://code.google.com/p/android/issues/detail?id=22493 и https://code.google.com/p/android/issues/detail?id=17343. Второй из них предполагает, что обходным путем является добавление «\ n» к тексту в текстовом представлении. Чтение этих страниц и ссылки на них могут помочь решить проблему для вас.

+0

спасибо, я решаю мою проблему .append текст в textview final String DOUBLE_BYTE_WORDJOINER = "\ u2060"; – Hemant

0

Почему вы установки высоты текстового окна вэнь вы щелкните Button1?

+0

высота текстового окна - моя тестовая строка, я удаляю ее. – Hemant

1

Проблема заключается в том

txtmain.setHeight(41); 

в первой кнопки мыши, так это изменит высоту TextView от WRAP CONTENT до фиксированного размера. Просто удалите его.

+0

высота текстового окна - это моя тестовая строка, я удаляю ее. Все проблемы возникают. Есть ли какое-либо решение. – Hemant

+0

работает мой код во всех os отлично, но в сэндвич с мороженым. – Hemant

Смежные вопросы