2017-08-25 3 views
0

チャットコーナーで楕円形の背景描画可能を作る、私はRelativeLayoutの背景には、この描画可能を追加します。Androidは、私は楕円形の背景を作成する方法を知っている

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" android:padding="10dp"> 
    <solid android:color="#FFFFFF"/> 
    <corners 
     android:bottomRightRadius="15dp" 
     android:bottomLeftRadius="15dp" 
     android:topLeftRadius="15dp" 
     android:topRightRadius="15dp"/> 
</shape> 

しかし、私は、この描画可能と、このようなチャットのコーナーを作成したいです:

oval image

どのように私はこの描画可能にチャットのコーナーを追加することができますか?

+0

あなたはおそらく '9-使用する必要がありますこのパッチの画像 –

+0

9パッチは何か分かりませんが、私にはそれが必要ですテキスト行によるレイアウト・スケール。 – user2983041

+0

@ user2983041私は解決策を掲載しました。それが動作しない場合私に教えてください –

答えて

2

この

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_margin="16dp" 
    android:orientation="vertical"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Hello" 
     android:padding="16dp" 
     android:background="@drawable/rounded_rect"/> 

    <ImageView 
     android:layout_marginTop="-1.5dp" 
     android:layout_width="8dp" 
     android:layout_height="16dp" 
     android:layout_gravity="start" 
     android:background="@drawable/corner" 
     /> 

</LinearLayout> 

Drawableのファイル

rounded_rect.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid android:color="#888" /> 
    <corners 
     android:bottomRightRadius="8dp" 
     android:topLeftRadius="8dp" 
     android:topRightRadius="8dp"/> 

</shape> 

corner.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <rotate 
      android:fromDegrees="45" 
      android:pivotX="135%" 
      android:pivotY="15%" 
      android:toDegrees="45" 
      > 
      <shape android:shape="rectangle"> 
       <solid android:color="#888"/> 

      </shape> 
     </rotate> 
    </item> 
</layer-list> 
のようなあなたのバブルのレイアウトを作成します。

このレイアウトは、あなたが、私はちょうど今、あなたの条件に矢印が左を指している必要があることに気づいたTextView

EDIT

に追加したテキストに合わせて拡張します。それがあなたのバブルのレイアウトにいくつかの小さな変更を加え得るために

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="16dp" 
    android:orientation="horizontal"> 

    <ImageView 
     android:layout_width="12dp" 
     android:layout_height="12dp" 
     android:layout_gravity="bottom" 
     android:background="@drawable/corner2" 
     /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Hello" 
     android:padding="16dp" 
     android:background="@drawable/rounded_rect"/> 

</LinearLayout> 

corner2.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <rotate 
      android:fromDegrees="-45" 
      android:pivotX="135%" 
      android:pivotY="15%" 
      android:toDegrees="45" 
      > 
      <shape android:shape="rectangle"> 
       <solid android:color="#888"/> 

      </shape> 
     </rotate> 
    </item> 
</layer-list> 

OUTPUT

enter image description here

+0

動作していない、私はコーナーが表示されません。 – user2983041

+0

あなたはどちらを試しましたか? 'corner1.xml'または' corner.xml'を使用しているファイル –

+0

@ user2983041あなたはdrawableファイルを正確に使ったことがありますか?それは動作するはずです。 –

1

コーナーを含めてチャットバブルを完全に描画可能にする必要があります。次に、9-patchにすると、ドロアブルは変形せずに水平方向と垂直方向に広がります。

関連する問題