[英]Android TableLayout row height or column stretch not working
I'm having a problem with TableLayout row height. 我遇到TableLayout行高问题。
If 如果
android:stretchColumns="1"
the result is 结果是
as you can see the text from the last row it's cut 正如你可以看到它被切割的最后一行的文字
if I don't specify stretchColumns
the result is: 如果我没有指定stretchColumns
,结果是:
the text it's now showing but the table (black) gets extremely big without content. 它现在显示的文字,但桌子(黑色)变得非常大,没有内容。
Here's the code: 这是代码:
<TableLayout
android:id="@+id/my_table"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"/>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_table_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="30dp"
android:weightSum="6" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:gravity="center" >
<ImageView
android:id="@+id/column_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3.9"
android:gravity="center_vertical|left" >
<TextView
android:id="@+id/column_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.7"
android:gravity="center_vertical|right" >
<TextView
android:id="@+id/column_three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textSize="18sp" />
</LinearLayout>
</TableRow>
I'm populating the rows and adding to the table programmatically. 我正在填充行并以编程方式添加到表中。
Why is this happening? 为什么会这样?
I hate this type of solutions but oh well... Instead of TableLayout I switch it to LinearLayout (both Table and Row) but the problem was the same. 我讨厌这种类型的解决方案但是很好......而不是TableLayout我将它切换到LinearLayout(表和行),但问题是相同的。 The difference is that with LinearLayout I just added one "empty row" and I achieve the goal. 不同之处在于使用LinearLayout我只添加了一个“空行”并实现了目标。 Tried the same approach with TableLayout and Rows but with no luck. 用TableLayout和Rows尝试了相同的方法,但没有运气。
@Francisco Corrales Morales @Francisco Corrales Morales
myLinearLayoutTable.addView((LinearLayout) inflater.inflate(R.layout.my_row, myLinearLayoutTable, false));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.