2012-09-10 8 views
0

두 부분으로 구성된 머리글과 본문이있는 레이아웃이 있습니다. 헤더는 TextView와 이미지를 포함합니다. 프로그래밍 방식으로 머리글 높이를 변경할 수 있습니다. 헤더의 이미지와 텍스트는 각각 크기를 조정해야합니다. 이미지 크기 조정은 괜찮지 만 텍스트는 크기 조정을 원하지 않습니다. Android에서 가능하고 어떻게 할 수 있습니까?TextView 글꼴 크기 자동 조절

내 레이아웃 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:tools="http://schemas.android.com/tools" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:id="@+id/header" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     tools:ignore="UseCompoundDrawables" > 

     <TextView 
      android:id="@+id/title_text" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/app_name" /> 

     <ImageView 
      android:id="@+id/edit_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:contentDescription="@string/edit" 
      android:src="@drawable/widget_edit" /> 
    </LinearLayout> 

    <TextView 
     android:id="@+id/content_text" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</LinearLayout> 
+0

아니요 xml을 사용할 수 없습니다. 당신은 아이폰의 scaleToFit을 참조하십시오 –

+0

시도해보십시오 http://stackoverflow.com/questions/5033012/auto-scale-textview-text-to-fit-within-bounds/17782522#17782522 –

답변

1

나는이 기본 텍스트 뷰와 실용적이라고 생각하지 않는다 - 적어도 몇 가지 해킹없이.

이 경우 사용자 정의보기 클래스를 사용하여 Canvas에 텍스트를 그려 봅니다. 그리기 호출 중에 캔버스의 정확한 너비와 높이를 알고 적절한 글꼴 크기로 텍스트를 그립니다.

1

프로그래밍 방식으로 높이를 변경하는 경우 수식을 정의하고 텍스트 크기를 계산할 수 있습니다. 그것은 독특한 방법입니다.

사용자 정의보기를 구현하고 부모의 높이에 따라 크기를 정의 할 수 있습니다.

존재할 수있는 종류의 단위가 존재합니다. sp (Scale-Independent Pixels). 그러나이 크기는 시스템에 설정된 텍스트의 크기와 같습니다.

+0

모두에게 감사합니다! 나는 생각할 것이다. – BArtWell

관련 문제