how to make columns in table layout spread evenly making maximum use of space available

妖精的绣舞 提交于 2019-12-20 17:48:13

问题


I was just trying out with table layout to display some data.... The data is a 3 column data and i want that the columns should utilize the whole width available. But it seems that the layout XML code which i had used is just wrapping up the columns according to the content.

Layout XML code

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >   
    <TableRow
        android:layout_width="fill_parent">
        <TextView
            android:padding="3dip"
            android:gravity="left"
            android:text="Name"
            />
        <TextView
            android:padding="3dip"
            android:gravity="left"
            android:text="Address"
            />

        <TextView
            android:padding="3dip"
            android:gravity="left"
            android:text="Age"
            />  
    </TableRow>
</TableLayout>

回答1:


You can try adding android:stretchColumns="0,1,2" to your <TableLayout> element.




回答2:


android:stretchColomns="0,1" is a good option. Also you can try using android:layout_span = "2" This will stretch the columns together depending on your value(Here it will span two columns together)



来源:https://stackoverflow.com/questions/2340647/how-to-make-columns-in-table-layout-spread-evenly-making-maximum-use-of-space-av

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!