如何添加边框表格布局? [英] how to add border around table layout?

查看:159
本文介绍了如何添加边框表格布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我下面的屏幕我的表code这个样子 http://imgur.com/dFP298o但我瓦纳​​做出这样的 http://imgur.com/YuYJiJx 如何我会添加各地的每一行边框和围绕表格布局?请大家帮我

 < TableLayout
         机器人:ID =@ + ID /表2
         机器人:layout_width =FILL_PARENT
           机器人:layout_below =@ + ID / test_button_text23
         机器人:layout_marginLeft =45dp
         机器人:layout_marginBottom =25dp
         机器人:layout_marginRight =45dp机器人:layout_height =FILL_PARENT
机器人:stretchColumns =*>     <的TableRow
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>    <的TextView
        机器人:重力=左
        机器人:文字=数量
        机器人:文字样式=大胆/>    <的TextView
        机器人:比重=中心
         机器人:文字样式=大胆
        机器人:文字=项目/> < /&的TableRow GT; < / TableLayout>
         < XML版本=1.0编码=UTF-8&GT?;
 <的TableRow的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =match_parent
 机器人:layout_height =match_parent> <的TextView
    机器人:ID =@ + ID / LOCALTIME
     机器人:文字颜色=#000000
    机器人:重力=左/> <的TextView
    机器人:ID =@ + ID / AP prentTemp
     机器人:文字颜色=#000000
    机器人:比重=中心/>
 < /&的TableRow GT;               查看排= getLayoutInflater()膨胀(R.layout.rows,NULL);
        ((的TextView)row.findViewById(R.id.localTime))。的setText(项目
                .getString(项目));
        ((的TextView)row.findViewById(R.id.ap prentTemp))的setText。(项目
                .getString(数量));


解决方案

为了创建一个围绕您的表行,并围着桌子布局的边界,你需要创建一个可绘制,作为一个边框,然后将其设置为背景你行。

例如:

RES /绘制/ border.xml

 <?XML版本=1.0编码=UTF-8&GT?;
<形状
   的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
   机器人:形状=矩形>
   [固体机器人:颜色=#000000/>
   <行程机器人:宽=1DP机器人:颜色=#000000/>
< /形状>

RES /布局/ your_layout.xml

 < TableLayout
     机器人:ID =@ + ID /表2
     机器人:layout_width =FILL_PARENT
     机器人:layout_below =@ + ID / test_button_text23
     机器人:layout_marginLeft =45dp
     机器人:layout_marginBottom =25dp
     机器人:layout_marginRight =45dp
     机器人:layout_height =FILL_PARENT
     机器人:stretchColumns =*>     <的TableRow
          机器人:layout_width =match_parent
          机器人:layout_height =match_parent
          机器人:背景=@绘制/边界>           <的TextView
              机器人:重力=左
              机器人:文字=数量
              机器人:背景=@绘制/边框
              机器人:文字样式=大胆/>           <的TextView
              机器人:比重=中心
              机器人:文字样式=大胆
              机器人:背景=@绘制/边框
              机器人:文字=项目/>     < /&的TableRow GT;< / TableLayout>

这不会完全一样您发布的图片,但用它玩得到你想要的东西。

this is my table code below my screen look like this http://imgur.com/dFP298o but i wana make like this http://imgur.com/YuYJiJx how i will add borders around each row and around table layout??? please help me

                <TableLayout
         android:id="@+id/table2"
         android:layout_width="fill_parent"
           android:layout_below="@+id/test_button_text23"
         android:layout_marginLeft="45dp"
         android:layout_marginBottom="25dp"
         android:layout_marginRight="45dp"

android:layout_height="fill_parent"
android:stretchColumns="*" >

     <TableRow
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:gravity="left"
        android:text="Quantity"
        android:textStyle="bold" />

    <TextView
        android:gravity="center"
         android:textStyle="bold"
        android:text="Item" />

 </TableRow>

 </TableLayout>     








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

 <TextView
    android:id="@+id/localTime"
     android:textColor="#000000"
    android:gravity="left" />

 <TextView
    android:id="@+id/apprentTemp"
     android:textColor="#000000"
    android:gravity="center" />


 </TableRow>





               View row = getLayoutInflater().inflate(R.layout.rows, null);
        ((TextView) row.findViewById(R.id.localTime)).setText(item
                .getString("Item"));
        ((TextView) row.findViewById(R.id.apprentTemp)).setText(item
                .getString("Quantity"));

解决方案

In order to create a border around your table rows and around the table layout, you need to create a drawable to serve as a border and then set it as a background to your rows.

For example:

res/drawable/border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape= "rectangle"  >
   <solid android:color="#000000"/>
   <stroke android:width="1dp"  android:color="#000000"/>
</shape>

res/layout/your_layout.xml

<TableLayout
     android:id="@+id/table2"
     android:layout_width="fill_parent"
     android:layout_below="@+id/test_button_text23"
     android:layout_marginLeft="45dp"
     android:layout_marginBottom="25dp"
     android:layout_marginRight="45dp"
     android:layout_height="fill_parent"
     android:stretchColumns="*" >

     <TableRow
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@drawable/border>

           <TextView
              android:gravity="left"
              android:text="Quantity"
              android:background="@drawable/border"
              android:textStyle="bold" />

           <TextView
              android:gravity="center"
              android:textStyle="bold"
              android:background="@drawable/border"
              android:text="Item" />

     </TableRow>

</TableLayout>  

This won't look exactly like the picture you posted, but play with it to get what you want.

这篇关于如何添加边框表格布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆