2016-12-29 5 views
0

私はチャットバブルを作ります。私は9patchイメージを使ってバブルを作りました。しかし、私はtextviewのサイズに応じてバブルのサイズを変更したい..どのようにそれを行うには?チャイルドテキストビューのサイズに応じて背景9パッ​​チ画像のサイズを変更するには

<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コードである...

+0

のマニュアルを参照してください。 – Noorul

+0

私は試しましたが、動作していません@Ahamed – Droid

+0

あなたのコードを編集しますか? – Noorul

答えて

0

あなたは、メソッドがint型の値を返すの下に、あなたが使用することができ、TextViewのリファレンスのメソッドの下に呼び出すことで、TextViewの高さ&幅を得ることができます画像のサイズを変更する。

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) 

は詳細親のレイアウトの背景を設定し https://developer.android.com/reference/android/view/View.html

関連する問題