android: how to display border of TableLayout

情到浓时终转凉″ 提交于 2019-12-11 01:19:48

问题


how can i highlight the border of the tablelayout... im using roundshape.xml which has shape as a background there must be some way by which i can give the border around your tablelayout...

roundshape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <corners android:radius="5dip" />

    <gradient
        android:angle="270"
        android:endColor="@color/WhiteSmoke"
        android:startColor="@color/WhiteSmoke"
        android:type="linear" />

</shape>

WhiteSmoke =#F5F5F5

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TableLayout
        android:layout_width="400dp"
        android:layout_height="400dp"
        android:background="@drawable/roundshape"
         >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </TableRow>

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </TableRow>
    </TableLayout>

</LinearLayout>

回答1:


i think this might help u.. go through code u will figure out the trick

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TableLayout
        android:layout_width="400dp"
        android:layout_height="400dp"
        android:background="@drawable/roundshape" >

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="1px"
            android:background="#ff9" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:text="" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="this is amazing" />
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="1px"
            android:background="#ff9" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:text="" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="this is amazing" />
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="1px"
            android:background="#ff9" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:text="" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="this is amazing" />
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="1px"
            android:background="#ff9" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:text="" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="this is amazing" />
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="1px"
            android:background="#ff9" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:text="" />
        </TableRow>
    </TableLayout>

</LinearLayout>



回答2:


There is a very similar post about this already here.

From David Jesse

My solution for this problem is to put an xml drawable resource on the background field of every cell. In this manner you could define a shape with the border you want for all cells. The only inconvenience is that the borders of the extreme cells have half the width of the others but it's no problem if your table fills the entire screen.

Here is the reference to this resource.



来源:https://stackoverflow.com/questions/11781723/android-how-to-display-border-of-tablelayout

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