2011-09-30 7 views
0

현재 체중이있는 구성 요소가 포함 된 활동을 진행 중입니다. 이러한 구성 요소에는 텍스트와 아이콘이 포함됩니다. 내가 아는 한, 안드로이드는 부모보기에 따라 텍스트 크기를 조정하는 기능을 제공하지 않습니다. 결과적으로 이러한 뷰를 측정 한 다음 수동으로 내 사용자 지정 글꼴을 TextViews에 적용하고 적절한 글꼴 크기를 설정해야합니다.Android 레이아웃 : 올바른 TextView 글꼴 크기를 선택하기 위해보기 측정

현재 실제로 작동하지만 실제로는 09-30 17 : 55 : 14.844 : 오류/ViewRoot (12893) : OutOfResourcesException 오류가 발생하여 오류가 발생하고 연결되어있을 수 있습니다. 내 방식대로. 에서 onCreate에서

: onGlobalLayout에서

LinearLayout mLayout = (LinearLayout) this.getLayoutInflater().inflate(R.layout.activity_main, null); 
    mLayout.getViewTreeObserver().addOnGlobalLayoutListener(this); 
    this.setContentView(mLayout); 

내가 측정을 할이 방법은

<RelativeLayout 
    android:layout_height="0dip" 
    android:layout_width="fill_parent" 
    android:layout_weight="0.35" 
    android:id="@+id/activity_main_row_1"> 
    <View 
     android:layout_width="6dip" 
     android:layout_height="fill_parent" 
     android:background="@color/palette_green" 
     android:layout_alignParentLeft="true" 
    /> 
    <RelativeLayout 
     android:layout_centerVertical="true" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:paddingLeft="20dip"> 
     <TextView 
      android:id="@+id/activity_main_row_1_title" 
      android:text="@string/title_add_expense" 
      android:textSize="10dip" 
      android:textColor="@color/palette_grey" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="0px"> 
     </TextView> 
     <TextView 
      android:id="@+id/activity_main_row_1_sub_title" 
      android:text="@string/subtitle_add_expense" 
      android:textSize="10dip" 
      android:textColor="@color/palette_dark_grey" 
      android:layout_alignParentLeft="true" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="0px" 
      android:layout_below="@+id/activity_main_row_1_title"> 
     </TextView> 
    </RelativeLayout> 
    <ImageView 
     android:id="@+id/activity_main_row_1_bracket" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/icon_bracket_right_grey" 
     android:paddingLeft="0dip" 
     android:paddingRight="0dip" 
     android:paddingTop="24dip" 
     android:paddingBottom="20dip" 
     android:layout_alignParentRight="true"> 
    </ImageView> 

</RelativeLayout> 

(여러 행이) 레이아웃에서 한 행입니다 :

@Override 
public void onGlobalLayout() { 

    int mRow1Height = mRow1.getHeight(); 
    <omitted> 


    if(mRow1Height>0) { 
     TextView row1Title = (TextView) findViewById(R.id.activity_main_row_1_title); 
     row1Title.setTypeface(mFontProvider.getTypeface()); 
     row1Title.setTextSize((float) ((mRow1Height)*.3)); 

     TextView row1SubTitle = (TextView) findViewById(R.id.activity_main_row_1_sub_title); 
     row1SubTitle.setTypeface(mFontProvider.getTypeface()); 
     row1SubTitle.setTextSize((float) ((mRow1Height)*.2)); 
    } 

내가하고 싶은 일을하는 올바른 방법일까요?

감사합니다.

건배

답변

1

OutOfResourcesExceptions의 원인이되는 문제점을 발견했습니다. onLayout에서 TextView의 텍스트를 설정합니다. 이로 인해보기가 다시 배치되어 무한 루프가 생깁니다.

그러나 addOnGlobalLayoutListener를 사용하고 있고 onLayout이 동적으로 크기가 조정 된 상위 뷰와 관련하여 TextViews의 크기를 조절할 수있는 유일한 방법 인 것에 대해 알고 싶습니다.