1
0

More than 1 year has passed since last update.

TextView内の設定でImageを設定する方法

Last updated at Posted at 2022-02-27

TextViewとImageViewを分けていましたが、TextView内にImageViewを設定し、コードを簡潔にすることができます!
早速コードで説明していきます!

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:layout_gravity="center"
        app:drawableEndCompat="@drawable/star"/>

</FrameLayout>

 スクリーンショット 2022-02-27 22.28.00.png

テキストの先頭にイメージを設定したい場合は

app:drawableStartCompat

テキストの後ろにイメージを設定したい場合は

app:drawableEndCompat

とTextView内に設定しましょう

また、テキストとイメージの間にスペースを作りたい場合は

android:drawablePadding=""

を一緒に設定し、もたせたいスペースを設定しましょう

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0