导航:首页 > 操作系统 > android表格边框

android表格边框

发布时间:2022-05-19 08:12:38

android TableRow加边框

应该是父布局的宽度有问题,你看看设置tablerower设置成一个固定的宽度看看.

Ⅱ android 怎么绘制表格边框

一、表格最蛋疼的就是那根线,网上有个很好的方法,大概思路是这样的:
1、给表格设置一个背景色(线的颜色)
2、给表格设置一个内边距(线的宽度的一半)
3、设置每一项内边距(线的宽度的一半)
3、给项的内容设置一个背景色(颜色不同于线即可)
显示效果大概是这样的:
二、数据的动态加载使用Adapter类,便与布局加载
自定义TableLayout加载的主体方法:
public void setAdapter(BaseAdapter baseAdapter, int column) {
if (baseAdapter == null || baseAdapter.getCount() == 0) {
return;
}
this.mAdapter = baseAdapter;
this.column = column;
drawLayout();
}

private void drawLayout() {
removeAllViews();
int realcount = mAdapter.getCount();
int count = 0;
if (realcount < column) {
count = column;
} else if (realcount % column != 0) {
count = realcount + column - (realcount % column);
} else {
count = realcount;
}
TableRow tableRow = null;//每一行的TableRow
for (int i = 0; i < count; i++) {
final int index = i;
View view = null;
if (index >= realcount) {
view = mAdapter.getView((realcount - 1), null, null);
view.setVisibility(View.INVISIBLE);
} else {
view = mAdapter.getView(index, null, null);
}
if (index % column == 0) {// 整行
tableRow = new TableRow(mContext);
}
if (tableRow != null) {//添加每一个Item
tableRow.addView(view);
}
if (index % column == 0) {// 整行
addView(tableRow, new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
}
}

三、使用和ListView的方式基本一样
public class MainActivity extends Activity {
private List<Map<String, Object>> dataList;
private TableBorderLayout layTable;
private String[] datas = new String[] { "疯狂", "个性", "张扬", "抖擞", "加油", "奋斗",
"努力", "精神" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
loadDatas();
}
private void initViews() {
layTable = (TableBorderLayout) findViewById(R.id.layTable);
}
private void loadDatas() {
dataList = new ArrayList<Map<String, Object>>();
Map<String, Object> item = null;
for (int i = 0; i < datas.length; i++) {
item = new HashMap<String, Object>();
item.put("Title", datas[i]);
dataList.add(item);
}
layTable.setAdapter(new MyAdapter(this, dataList));
}
}

Ⅲ android怎么给tablerow添加边框

总结一下android ui界面里面如何设置边框,以及如何把边框设置成弧形的即圆角。
其实,android的ui里,界面一般都是比较简单的,不会像web页面那样,数据量比较大,关于给android界面(表格)设置边框,其思想很想我们用HTML设计表格然后给它设置边框,如果你懂html的话。即通过给不同的控件设置背景颜色来反衬出边框线
以一个登录界面为例,设置一个有边框线的android 登录界面:
注:本例要求的只是将该TableLayout中的行与行之间用边框线隔开
此例中,采用TableLayout布局,非常简单,里面有3个TableRow,分别放置 用户名、密码、登录按钮,根据上面说的设置边框线只需要设置控件的背景颜色即可。这个例子中要求行与行之间有边框线,那么,就这么想,
TableLayout:是该界面的布局管理器(当然也是一个控件),放在最外层,那么这时你可以给它选一个背景颜色参考注释 a)
TableRow:是表格中的一行,设置边框线重点就在此,它是紧跟着TableLayout的,可以给TableRow(行)设置背景色,参考b)
TableLayout与TableRow关系:可以看成父与子的关系,那么不管怎么样,TableLayout总是大于TableRow,那么通过给二者设置不同的颜色,设置颜色的时候可以让子组件(TableRow)周围稍微留出一点边界(就是它的背景色不会覆盖完整个行,如何让它显示成这样呢=====>android:layout_margin="0.5dip"[此属性即是设置该组件周围留出一点边界])
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout
android:id="@+id/widget30"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffcccccc" //a)给tablelayout设置背景色,改背景颜色将会是你要设置的边框线的背景色
android:layout_margin="1dip"
>
<!--android:background="@drawable/view_shape" -->
<TableRow
android:id="@+id/widget40"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffcc99" //b)给tablerow设置背景色
android:layout_margin="0.5dip" //c)非常重要的一点
>
<TextView
android:id="@+id/widget41"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Name"
android:textStyle="bold"
android:layout_gravity="center_vertical" //如果想让表格里的列与列(column之间)也有边框线隔开,则同上面一样也要设置android:background="#ffffcc99"与android:layout_margin="0.5dip"
>
</TextView>
<EditText
android:id="@+id/widget42"
android:layout_width="141px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:background="#ffffffff"
android:textColor="#ff000000"
>
</EditText>
</TableRow>
<TableRow
android:id="@+id/widget43"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffcc99"
android:layout_margin="0.5dip"
>
<TextView
android:id="@+id/widget44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textStyle="bold"
>
</TextView>
<EditText
android:id="@+id/widget45"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:background="#ffffffff"
android:textColor="#ff000000"
>
</EditText>
</TableRow>
<Button
android:id="@+id/widget46"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textStyle="bold"
android:textColor="#ff000000"
android:layout_margin="2dip"
android:background="#ffffcc33"
>
<!--android:background="@drawable/view_shape" -->
</Button>
</TableLayout>

Ⅳ 怎么给android 设置边框

  1. android设置边框利用内容的margin或者padding的留白加容器的背景来实现边框效果。

  2. shape来实现边框效果

  3. corners是设置边框圆角

  4. stroke是描边的

  5. layer-list实现自由边框

嵌套一层,利用内容的margin或者padding的留白加容器的背景来实现边框效果。其实这个道理很简单,很早的时候那时候我们还用table做html页面布局的时候,我们就是使用cellspacing来实现table的边框的。现在我们也利用同样的想法来实现。

当然内部的容器也是需要有颜色的,如果想实现内部透明的效果则需要将内部View的背景色跟背景的颜色保持一致,这是不太方便的地方。


在Android中,给一个控件(或View)设置背景主要是通过background:xxx属性来完成。background的参数一般来说是一个drawable资源。


给控件设置边框最简单的方式就是把background设置成你预先设计好的带圆角和边框的背景图。但是这种方法的缺点是没有灵活性,不同大小的view要不同尺寸的图片,还要去适应不同分辨率的设备。


3使用9-patch(九宫格)的背景图片来实现边框效果。


做一个有边框的9-patch图片,作为要有边框的View的背景图即可。这样你还可以控制哪边有边框,哪边无边框,这种方法是比较好的一种方法,而且没有多余的View嵌套。另外你还可以实现圆角边框等效果。


4利用shape来实现边框效果。


当然你可以使用shape中的stroke来实现border的效果。


/res/drawable/filename.xml


只要引用这个shape作为背景图片即可。


5.layer-list实现自由边框

当前版本的Android

SDK并没有给stroke提供bottom、left、right之类的属性,也就是说你无法通过它来让长方形的边框少于4条。于是有人想出了这个方法。


android:width="1dp"


android:color="#333"/>


android:left="1dp"


android:top="1dp"


android:right="1dp"


android:bottom="1dp">


android:color="#FFF"/>


在第二个item中定义的top,left...就是对应的边框,不设置即没有边框。

Ⅳ android表格布局如何添加excel边框 求代码,求图,谢谢各位大侠!

Ⅵ 怎么给android 设置边框

Android控件设置边框的该如下:
1. 在drawable新建一个 buttonstyle.xml的文件,内容如下:
<?xml vers
ion="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 连框颜色值 --><item>
<shape>
<solid android:color="#ff0000" />
</shape>
</item>
<!-- 主体背景颜色值 -->
<item android:bottom="3dp" android:right="3dp">
<shape>
<solid android:color="#ffffff" />
<padding android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
</item>
</layer-list>

2.然后在布局文件里面引入这个xml,示例代码如下:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1"
android:background="@drawable/buttonstyle" />

Ⅶ android怎么让gridview有边框线

gridview有边框线通过设置里面控件的backgroud,也就是边框。通过shape设置。

下面例子来自于android学习手册,android学习手册包含9个章节,108个例子,源码文档随便看,例子都是可交互,可运行, 源码采用android studio目录结构,高亮显示代码,文档都采用文档结构图显示,可以快速定位。360手机助手中下载,图标上有贝壳。

java"><?xmlversion="1.0"encoding="utf-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android">

<!--圆角-->
<corners
android:radius="9dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:bottomRightRadius="2dp"/><!--设置圆角半径-->

<!--渐变-->
<gradient
android:startColor="@android:color/white"
android:centerColor="@android:color/black"
android:endColor="@android:color/black"
android:useLevel="true"
android:angle="45"
android:type="radial"
android:centerX="0"
android:centerY="0"
android:gradientRadius="90"/>

<!--间隔-->
<padding
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/><!--各方向的间隔-->

<!--大小-->
<size
android:width="50dp"
android:height="50dp"/><!--宽度和高度-->

<!--填充-->
<solid
android:color="@android:color/white"/><!--填充的颜色-->

<!--描边-->
<stroke
android:width="2dp"
android:color="@android:color/black"
android:dashWidth="1dp"
android:dashGap="2dp"/>

</shape>

Ⅷ 怎么实现一个布局页面中的表格边框

这样定义就有边框了:

android:layout_width="fill_parent"
android:layout_height="fill_parent" >

android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textSize="15px" />

android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textSize="15px" />

Ⅸ 怎么给android 设置边框

边框主要是使用shape文件,可以定制左右上下的边框,如果想要隐藏某部分,设置我透明即可。

Ⅹ android的PopupWindow怎么添加边框

popUpWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.page2));
设置的是popupwindow(window容器)的背景。
popUpWindow = new PopupWindow(show_popvieView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); //是将show_popvieView放入容器中,以自适应作为大小,且容器也采用自适应。
综上,如果你设置大小,导致show_popvieView沾满整个屏幕,那么window容器最为底层,设置的背景坑定是看不见的。
建议:背景设置采用设置show_popvieView的背景。如果有多层,可以在内容里面镶嵌,最好别直接设置外层popupwindow容器

阅读全文

与android表格边框相关的资料

热点内容
解压小熊手机壳 浏览:345
成都市区建成面积算法 浏览:660
智能家居单片机 浏览:97
买男装用什么app好 浏览:855
文件夹合并了怎么拆开 浏览:260
波段副图源码无未来函数 浏览:88
livecn服务器地址 浏览:259
程序员这个工作真的很吃香吗 浏览:846
程序员和数学分析师待遇 浏览:680
压缩气弹簧怎么拆 浏览:322
华为公有云服务器添加虚拟ip 浏览:211
程序员和运营哪个累 浏览:26
抖音安卓信息提示音怎么设置 浏览:456
光速虚拟机的共享文件夹 浏览:251
程序员培训机构发的朋友圈真实性 浏览:744
天干地支简单算法 浏览:299
下载个压缩文件 浏览:300
普通人电脑关机vs程序员关机 浏览:630
米酷建站源码 浏览:115
氢气app怎么搜搭配 浏览:619