Skip to content

Instantly share code, notes, and snippets.

@Sukhobrusov
Created November 14, 2023 15:07
Show Gist options
  • Save Sukhobrusov/af5608c520056e114743215eca1631f0 to your computer and use it in GitHub Desktop.
Save Sukhobrusov/af5608c520056e114743215eca1631f0 to your computer and use it in GitHub Desktop.
TableLayout, TextView.text with 0f width and 1 weight is cut when pressed by other views
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:showDividers="beginning|middle|end"
android:padding="5dip"
android:id="@+id/table"
android:isScrollContainer="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow
android:showDividers="beginning|middle|end"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="fill"
tools:textSize="14sp"
tools:textColor="@color/white"
tools:textStyle="bold"
tools:text="some text withing a text to add the text until there is no s\n
pace left for the other views and this can go on and on for\n
a long width. The key factor is the \\n. and the fact that \n
primary views WIDTH is WRAP_CONTENT\n when other views in its container are 0dp width and 1f\nweight" />
<TextView
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="4dp"
android:layout_gravity="fill"
tools:textSize="14sp"
tools:textColor="@color/red_span"
tools:textStyle="bold"
tools:text="some text" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:text="some text" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:text="some text" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:text="some text" />
</TableRow>
</TableLayout>
@Sukhobrusov
Copy link
Author

image

@Sukhobrusov
Copy link
Author

If I keep adding more views the content is gets squished more
image

@Sukhobrusov
Copy link
Author

<TextView android:layout_width="10dp" />
Table
- Row
- - Text wrap_content
- - Text 10dp
- - Text 10dp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment