N.W.A
N.W.A

Reputation: 75

Text aligning and cutting of if too long

I'm creating an app and i want the text to allign under a button, it looks like this: enter image description here

so i want the large text starting on the left at(5dp) under the button and end at(155dp from the left) the end of the button. And if the text is too long to fit under the button, i don't want it to go in the next line, i want it to cut of and put in ".." at the end so, that it looks like this f.e. "Large T..", i photoshoped that picture real quick to show you what i mean:

enter image description here

I'm kind of new to xml and the whole ndroid app scene, so any help is appreciated :)

Upvotes: 1

Views: 70

Answers (2)

Rohit Sharma
Rohit Sharma

Reputation: 2017

In your TextView add these properties:

android:ellipsize="end"
android:maxEms="8"
android:singleLine="true"

NOTE: You can adjust the ems size to how many chars you want to show.

Upvotes: 1

daniel.keresztes
daniel.keresztes

Reputation: 885

Use LinearLayouts with layout_wight. Example code below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="match_parent"
android:layout_height="match_parent">

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

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@android:drawable/ic_menu_save"/>

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@android:drawable/ic_menu_save"/>

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@android:drawable/ic_menu_save"/>


</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:orientation="horizontal">

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="true"
        android:text="LOOOOOOOOOOOOOOOOOOOOONG"/>

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="true"
        android:text="LOOOOOOOOOOOOOOOOOOOOONG"/>

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="true"
        android:text="LOOOOOOOOOOOOOOOOOOOOONG"/>


</LinearLayout>

Result will be:

enter image description here

Upvotes: 1

Related Questions