2013-05-08 1 views
0

버튼을 클릭 할 때 텍스트 크기를 변경하려고합니다. XML은 : 아이스크림 샌드위치의 동적 textsize 변경

<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" /> 
내 코드입니다 : 내가 버튼 1을 클릭

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(); 
     } 
    }); 

, 그것은 적절한 출력을 제공하지만 출력을 button1을 클릭 한 후 버튼 2를 클릭하면 변경.

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=22493https://code.google.com/p/android/issues/detail?id=17343 참조). 두 번째 방법은 텍스트보기의 텍스트에 "\ n"을 추가하는 것입니다. 해당 페이지와 링크 된 페이지를 읽으면 문제를 해결하는 데 도움이 될 수 있습니다.

+0

고마워, 내 문제 .append 텍스트를 textview에 최종 문자열 DOUBLE_BYTE_WORDJOINER = "\ u2060"; – Hemant

0

왜 텍스트 상자 높이 혹 당신이 Button1을 클릭하여 설정된다 : 여기

내 출력?

+0

텍스트 상자 높이가 내 테스트 라인, 나는 그것을 제거합니다. – Hemant

1

문제 먼저 버튼 클릭에

txtmain.setHeight(41); 

이므로은 고정 크기로 WRAP CONTENT에서 텍스트 뷰의 높이를 변경한다. 그냥 제거하십시오 ..

+0

텍스트 상자 높이가 내 테스트 라인입니다, 나는 그것을 제거합니다. 문제는 발생합니다. 거기에 어떤 해결책이 있습니다. – Hemant

+0

아이스크림 샌드위치에 완벽하게 모든 OS에서 내 코드를 실행합니다. 다른 출력. – Hemant

관련 문제