I am creating an android application for displaying contact details of all the services which are available in my city. I am using drawer in my application for navigation of cities. But TextView having longer text (e.g. Adress) goes out of the screen. So please help me so that TextView should be fit in the screen. Below is my code for that activity:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Name: "
android:id="@+id/textView27"
android:layout_row="0"
android:layout_column="0"
style="@style/Base.TextAppearance.AppCompat.Title"
android:textSize="22dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Idea Gallery"
android:id="@+id/textView28"
android:layout_row="0"
android:layout_column="1"
android:textSize="22dp" />
<TextView
style="@style/Base.TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Address: "
android:id="@+id/textView29"
android:layout_row="1"
android:layout_column="0"
android:textSize="22dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Shop No 5, Akshay Apartment, Kalwa, Thane - 400605, Opposite Pramila Hospital "
android:id="@+id/textView30"
android:layout_row="1"
android:layout_column="1"
android:textSize="22dp" />
<TextView
style="@style/Base.TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Contact:"
android:id="@+id/textView31"
android:layout_row="2"
android:layout_column="0"
android:textSize="22dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="022 - 38539146"
android:id="@+id/textView32"
android:layout_row="2"
android:layout_column="1"
android:textSize="22dp" />
</GridLayout>
Add the following attributes to your TextView
elements:
android:layout_width="0dp"
android:layout_gravity="fill_horizontal"
This will make the TextView
s fill the cell's width, and not further.
I applied it on the gray labels here:
Add this to your TextView's
android:ellipsize="end"
android:maxLines="1"
What this does is , If your Text is long it will show it in dots. for Example : Nadim Shaikh will be Nadim SH...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With