Issue
- I am trying a display a single letter on a
TextView
. - Here
TextView
is having abackground drawable
with a border butTextView
expands and shrinks based on that single letter and I don't want that.
My layout code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp">
<TextView
android:id="@+id/txt_letter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/drawable_bg"
android:fontFamily="@font/viga"
android:padding="@dimen/padding_16dp"
android:text="A"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
drawable_bg.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F5F5F5" />
<stroke
android:width="1dp"
android:color="#9E9E9E" />
<corners android:radius="4dp" />
<padding
android:bottom="8dp"
android:left="20dp"
android:right="20dp"
android:top="8dp" />
</shape>
Solution
You're using wrap_content
so the size is change according to the text. Simply use fixed dimension
<TextView
android:id="@+id/txt_letter"
android:layout_width="20dp" // fixed size
android:layout_height="20dp" // fixed size
android:background="@drawable/drawable_bg"
android:fontFamily="@font/viga"
android:padding="@dimen/padding_16dp"
android:text="A"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
Answered By - Trung Nguyen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.