Sujith S Manjavana
Sujith S Manjavana

Reputation: 1596

android textview contents off screen

In my video player i have three textviews (title , battery percentage, time). The problem is the time text getting trimmed when title text is too long. How to fix this? is there is any solution to dynamically adjust the textview length and positions? Here is my code and screenshot---

<LinearLayout
        android:id="@+id/top_panel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="#45000000"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/title_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:lines="1"
            android:text="abcdefghijklmnopqrstuvwxyz1234567"
            android:paddingLeft="5dp"
            android:textColor="#ffffff"
            android:textSize="15sp"
            android:textStyle="bold" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/batPer"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
               android:layout_marginRight="8dp"
                android:lines="1"
                android:text="100%"
                android:textSize="17sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/timetxt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:lines="1"

                android:text="03:07AM"
                android:textColor="#ffffff"
                android:textSize="17sp"
                android:textStyle="bold" />
        </LinearLayout>
    </LinearLayout>

enter image description here

Upvotes: 0

Views: 1709

Answers (3)

Piyush
Piyush

Reputation: 18923

Change this way by using Weight.

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/batPer"
            android:layout_weight=".7"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
           android:layout_marginRight="8dp"
            android:lines="1"
            android:text="100%"
            android:textSize="17sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/timetxt"
            android:layout_weight=".3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:lines="1"
            android:text="03:07AM"
            android:textColor="#ffffff"
            android:textSize="17sp"
            android:textStyle="bold" />
</LinearLayout>

Upvotes: 1

SilentKiller
SilentKiller

Reputation: 6942

You should change LinearLayout to RelativeLayout. as well as you can assign android:ellipsize="marquee" or android:ellipsize="end" to the First title_txt

Even I had changed the width of LinearLayout containing Battery Percentage and Timer from android:layout_width="fill_parent" to android:layout_width="wrap_content"

doesn't matter your text of title increase or decrease timer and and percentage will remain at the right side.

Try With Following Code.

<RelativeLayout 
    android:id="@+id/top_panel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:background="#45000000"
    android:gravity="center_vertical"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/title_txt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/ll_timer_battery_perc"
        android:ellipsize="marquee"
        android:lines="1"
        android:marqueeRepeatLimit="marquee_forever"
        android:paddingLeft="5dp"
        android:text="abcdefghijklmnopqrstuvwxyz1234567"
        android:textColor="#ffffff"
        android:textSize="15sp"
        android:textStyle="bold" />

    <LinearLayout
        android:id="@+id/ll_timer_battery_perc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:gravity="right"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/batPer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:lines="1"
            android:text="100%"
            android:textSize="17sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/timetxt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:lines="1"
            android:text="03:07AM"
            android:textColor="#ffffff"
            android:textSize="17sp"
            android:textStyle="bold" />
    </LinearLayout>

</RelativeLayout>

Upvotes: 2

Smokez
Smokez

Reputation: 382

You're using android:lines="1" which makes text get trimmed if longer than one line. You should remove this or extend to 2 lines if you want the text to fit the textview and all be displahed

Upvotes: 1

Related Questions