2013-08-06 3 views
0

텍스트보기에서 이미지 추가가 작동합니다. 이미지 높이와 너비를 텍스트보기로 변경 텍스트 높이가 작동하지 않습니다. (원본 이미지 "빨간색 원은": 32px X 32px)Android - 비트 맵 높이 = 텍스트 뷰 텍스트 높이?

출력은 다음과 같습니다

test img http://img850.imageshack.us/img850/9500/m1f.png

XML :

<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="20sp" /> 

코드 :

TextView textView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    textView = (TextView)findViewById(R.id.textView); 
} 

@Override 
public void onWindowFocusChanged(boolean hasFocus) { 
    // TODO Auto-generated method stub 
    super.onWindowFocusChanged(hasFocus); 

    String getText = getResources().getString(R.string.getText); 

    textView.setText(getText); 

    SpannableStringBuilder ssb = new SpannableStringBuilder(getText); 

    Bitmap redcircle= BitmapFactory.decodeResource(getResources(), R.drawable.redcircle); 

    Bitmap resizedbitmap = Bitmap.createScaledBitmap(redcircle, (int)textView.getMeasuredHeight(), (int)textView.getMeasuredHeight(), true); 
    ssb.setSpan(new ImageSpan(resizedbitmap), 3, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE);  

    textView.setText(ssb, BufferType.SPANNABLE);  
} 

편집을 :

나는 이미지 높이와 너비가 텍스트보기 텍스트 높이와 동일하다는 것을 알고 싶다. 이 같은 예를 들어

test img 2 http://img849.imageshack.us/img849/3163/r9x.png

+0

textView.getMeasuredHeight() 대신 textView.getLineHeight()를 사용하십시오. –

답변

1

ImageSpan(resizedbitmap, ImageSpan.ALIGN_BASELINE) 

대신 ImageSpan의 기본 정렬이 ALIGN_BOTTOM입니다

ImageSpan(resizedbitmap) 

로 사용해보십시오.

+0

Ok. 그러나 이미지 크기는 같습니다. 텍스트보기 높이를 가져 오지 않습니다. – Johnny

+1

@ user2080833 - 스타일이 지정된 텍스트를 사용하면 이미지가 텍스트의 일부가됩니다. 텍스트보기에 패딩이 있으면 해당 패딩이 이미지에도 적용됩니다. 아마도 당신이 달성하고자하는 그림을 게시 할 수 있습니다. –