-1

I have a status bar with 6 elements in a row in a linear layout. This looks ok on a newer display with high resolution. But when I start the app on my old smartphone only the first text of the Textview in the status bar is shown. The imageViews are cut off and the status bar gets higher without extra content.

What I want is, that if the content does not fit, the text in the first textView is shorten, so that the ImageViews can all be shown. Is this possible?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="2dp"
    android:gravity="right|center_vertical"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/statusbar_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp"
        android:text="Text der Statusbar" />

    <TextView
        android:id="@+id/statusbar_text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp"
        android:text="TEXT1" />

    <ImageView
        android:id="@+id/some_state0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/stat_some_state0" />

    <ImageView
        android:id="@+id/some_state1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp" 
        android:src="@drawable/stat_some_state1" />

    <ImageView
        android:id="@+id/some_state2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp" 
        android:src="@drawable/stat_some_state2" />

    <ImageView
        android:id="@+id/some_state3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp" 
        android:src="@drawable/stat_some_state3" />

</LinearLayout>
partisan
  • 42
  • 8

2 Answers2

0

Add weight for all elements . If weights are equal the Layout will be divided equally. if weight is twice the others then the division will be twice. if orientation is vertical and you had given weight then height should be 0dp and if it is horizontal , width should be 0dp

?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="2dp"
    android:gravity="right|center_vertical"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/statusbar_text"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp"
        android:layout_weight="1"
        android:text="Text der Statusbar" />

    <TextView
        android:id="@+id/statusbar_text1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingLeft="5dp"
        android:text="TEXT1" />

    <ImageView
        android:id="@+id/some_state0"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/stat_some_state0" />

    <ImageView
        android:id="@+id/some_state1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingLeft="5dp" 
        android:src="@drawable/stat_some_state1" />

    <ImageView
        android:id="@+id/some_state2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingLeft="5dp" 
        android:src="@drawable/stat_some_state2" />

    <ImageView
        android:id="@+id/some_state3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingLeft="5dp" 
        android:src="@drawable/stat_some_state3" />

</LinearLayout>
Tomin B Azhakathu
  • 2,656
  • 1
  • 19
  • 28
0

you should make your layout like this. adding weight to the views will fix their widths. So no matter the text length it won't disturb your imageViews.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:gravity="right|center_vertical"
android:orientation="horizontal">

<TextView
    android:id="@+id/statusbar_text"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:paddingLeft="5dp"
    android:text="Text der Statusbar" />

<TextView
    android:id="@+id/statusbar_text1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:paddingLeft="5dp"
    android:text="TEXT1" />

<ImageView
    android:id="@+id/some_state0"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.5"
    android:src="@drawable/stat_some_state0" />

<ImageView
    android:id="@+id/some_state1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.5"
    android:paddingLeft="5dp"
    android:src="@drawable/stat_some_state1" />

<ImageView
    android:id="@+id/some_state2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.5"
    android:paddingLeft="5dp"
    android:src="@drawable/stat_some_state2" />

<ImageView
    android:id="@+id/some_state3"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.5"
    android:paddingLeft="5dp"
    android:src="@drawable/stat_some_state3" />

</LinearLayout>
Umair
  • 6,366
  • 15
  • 42
  • 50