I have a LinearLayout
that covers the entire width of the screen, inside I have a random number of TextView
(7 in this example). I want all the TextView
are the same size, so I put the attribute android:layout_weight="1"
in each.
When there is not text in the TextView everything works fine:
but when I add the text corresponding to each TextView
, the size of Textview
change, not keep the weight and resize the LinearLayout
This is only part of the design of my Activity, so I recreated it in a new xml to see if the error persists.
And I have noticed that this only happens when the LinearLayout
is inside of a HorizontalScrollView
When it is not, I get the expected result:
My xml:
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:singleLine="true"
android:text="LONG TEXT"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#009FDC"
android:gravity="center"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff"
android:textStyle="bold"
android:typeface="serif" />
<TextView
android:singleLine="true"
android:layout_marginLeft="1dp"
android:text="LONG TEXT"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#009FDC"
android:gravity="center"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff"
android:textStyle="bold"
android:typeface="serif" />
<TextView
android:singleLine="true"
android:layout_marginLeft="1dp"
android:text="LONG TEXT"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#009FDC"
android:gravity="center"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff"
android:textStyle="bold"
android:typeface="serif" />
<TextView
android:singleLine="true"
android:layout_marginLeft="1dp"
android:text="LONG TEXT"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#009FDC"
android:gravity="center"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff"
android:textStyle="bold"
android:typeface="serif" />
<TextView
android:singleLine="true"
android:layout_marginLeft="1dp"
android:text="LONG TEXT"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#009FDC"
android:gravity="center"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff"
android:textStyle="bold"
android:typeface="serif" />
<TextView
android:singleLine="true"
android:layout_marginLeft="1dp"
android:text="LONG TEXT"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#009FDC"
android:gravity="center"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff"
android:textStyle="bold"
android:typeface="serif" />
<TextView
android:singleLine="true"
android:layout_marginLeft="1dp"
android:text="LONG TEXT"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#009FDC"
android:gravity="center"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff"
android:textStyle="bold"
android:typeface="serif" />
</LinearLayout>
</HorizontalScrollView>
Anyone know how to fix this? thanks in advance.