TextView: wrap_content + отступ?
Делаю закругленный TextView. Использую wrap_content, но текст налазит на границы.
Возможно, есть несложный способ сделать wrap_content + отступы по краям? +5dp к примеру. ниже код.
rounded.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#C8A032" />
<corners android:radius="20dp" />
<stroke
android:width="3dip"
android:color="#FF5A4C24" />
</shape>
и кусок из основного лайаута:
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@drawable/rounded"
android:gravity="center"
android:text="TextView" />
Ответы (1 шт):
Автор решения: Sergei Buvaka
→ Ссылка
Используйте padding.
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingEnd="10dp"
android:paddingStart="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:background="@drawable/rounded"
android:gravity="center"
android:text="TextView" />
margin- это внешний отступ (снаружи от границ View до остальных элементов)
padding - это внутренний отступ (внутри от границ View)

