2016-12-29 1 views
0

채팅 버블을하고 있습니다. 나는 9patch 이미지를 사용하여 버블을 만들었습니다. 하지만 Textview의 크기에 따라 거품의 크기를 조정하고 싶습니다. 어떻게해야합니까?배경 이미지의 크기를 변경하는 방법 자식 텍스트 뷰의 크기에 따라 9patch 이미지

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    > 

    <LinearLayout 
android:background="@drawable/senderbubble2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:paddingBottom="10dp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentStart="true"> 

     <TextView 
      android:id="@+id/txt_msg" 
      android:text="hello world" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="5dp" 
      android:textColor="#000000" /> 

    </LinearLayout> 

</RelativeLayout> 

위는 채팅 거품의 내 XML 코드 ... 방법은 int 값을 반환 아래

+0

에 대한

textView.getMeasuredHeight(); textView.getMeasuredWidth(); If you want the height/width of text in textView you can try Rect bounds = new Rect(); textView.getPaint().getTextBounds(textView.getText().toString(), 0, textView.getText().length(), bounds) 

참조 설명서를 참조하십시오. – Noorul

+0

시도했지만 그 작동하지 @Ahamed – Droid

+0

코드를 편집해야합니까? – Noorul

답변

관련 문제