189 8069 5689

android表格控件,Android 表格

android这么多ui控件怎样才能记牢呢

布局(Layout)的概念是针对Activity的,Activity就是布满整 个Android设备的窗口或者悬浮于其他窗口上的交互界面。在一个应用程序中通常由多个Activity构成,每个需要显示的Activity都需要在AndroidManifest.xml文件之中声明。

成都创新互联公司主要从事成都做网站、网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务善右,十年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108

通常情况下,开发人员可以使用两种方式来创建UI组件,一种方式是使用XML方式来配置UI组件的相关属性,然后装载这些UI组件,这也是最常用的方式。但是有些特殊情况下,需要动态生成UI组件,则需要使用第二种方式,完全使用Java代码来创建UI组件。

XML布局文件是Android系统中定义的Layout的常用方式,所有布局文件必须包含在res/layout目录中,且必须符合Java的命名 规范。当在res/layout目录下新增了布局文件之后,R.java文件会自动收录该布局资源,Java代码可通过setContentView方法 在Activity中显示该Layout。

setContentView(R.layout.资源名称);

在布局文件中可以指定UI组件的android:id属性,该属性的属性值代表该组件的唯一标识。通过Activity.findViewById()访问,并且findViewById()必须在setContentView加载xml文件之后使用,否则会抛出异常。

findViewById(R.id.)

Android应用的绝大部分UI组件都放在android.widget包及其子包、android.view包及其子包中,Android应用的 所有UI组件都继承了View类。View类还有一个重要的子类:ViewGroup,ViewGroup类是所有布局管理器的父类。

ViewGroup容器控制其子组件的分布依赖于ViewGroup.LayoutParams、ViewGroup.MarginLayoutParams两个内部类。

ViewGroup.LayoutParams提供两个XML属性设定组件的大小。

android:layout_height:指定该子组件的基本高度;

android:layout_width:指定该子组件的基本宽度。

这两个属性有三个基本值,这两个属性有三个特定的值:

fill_parent:指定组件的高度、宽度与父容器组件的一样。

match_parent:与fill_parent一样,Android2.2开始推荐使用。

warp_content:内容包裹。

ViewGroup.MarginLayoutParams用于控制子组件周围的页边距。

android:layout_marginBottom(下边距);

android:layout_marginLeft(左边距);

android:layout_marginRight(右边距):

layout_marginTop(上边距)

对于View的尺寸,android提供了三种单位供选择使用:

px:像素。

dp:dpi,表示屏幕实际的像素。

sp:与scale无关的像素,与dp类似。

尺寸单位选择的技巧:如果设置长度、高度等属性时可以使用dp或sp,但是如果设置字体,需要使用px。如果使用dp或sp,系统会根据屏幕密度的变化进行转换。

为了适应各种界面风格,Android提供了五种布局规范,利用这五种布局,基本上可以在设备上随心所欲的摆放任何UI组件,这五种布局分别是:

FrameLayout(帧布局)。

LinearLayout(线性布局)

RelativeLayout(相对布局)。

TableLayout(表格布局)。

AbsoluteLayout(绝对布局)。

线性布局(LinearLayout)

LinearLayout是最常用的布局方式,在XML文件中使用标记。它会将容器里的UI组件一个一个挨着排列起来。但是LinearLayout不会换行,当UI组件超出屏幕之后,则不会被显示出来。LinearLayout有两个重要的XML属性:androidgravity(对齐方 式);android:orientation(排列方式)。

android:orientation(排列方式),设定了LinearLayout中包含的UI组件的排列方式,有两个选项vertical(竖向)、horizontal(横向,默认值)

android:gravity(对齐方式),设定LinearLayout中包含UI组件的对齐方式,其选项很多,常用上(top)、下(bottom)、左(left)、右(right)。

android实现复杂table表格合并单元格?

可以通过Tablelayout布局的layout_span属性实现,layout_span指定该单元格占据的列数

1、Tablelayout简介

Tablelayout类以行和列的形式对控件进行管理,每一行为一个TableRow对象,或一个View控件。当为TableRow对象时,可在TableRow下添加子控件,默认情况下,每个子控件占据一列。 当为View时,该View将独占一行。

2、TableLayout行列数的确定

    TableLayout的行数由开发人员直接指定,即有多少个TableRow对象(或View控件),就有多少行。

 TableLayout的列数等于含有最多子控件的TableRow的列数。如第一TableRow含2个子控件,第二个TableRow含3个,第三个TableRow含4个,那么该TableLayout的列数为4.

3、TableLayout可设置的属性详解

TableLayout可设置的属性包括全局属性及单元格属性。

单元格属性,有以下2个参数:

android:layout_column    指定该单元格在第几列显示

android:layout_span        指定该单元格占据的列数(未指定时,为1)

示例:

android:layout_column="1"    该控件显示在第1列

android:layout_span="2"        该控件占据2列

4、一个TableLayout布局的实例

?xml version="1.0" encoding="utf-8"?  

LinearLayout xmlns:android=""  

android:orientation="vertical"  

android:layout_width="fill_parent"  

android:layout_height="fill_parent"  

android:padding="3dip"  

!-- 1个TableLayout,用于描述表中单元格的属性,包括:android:layout_column 及android:layout_span--  

TextView   

android:text="表:单元格设置:指定单元格属性设置"  

android:layout_height="wrap_content"   

android:layout_width="wrap_content"  

android:textSize="15sp"  

android:background="#7f00ffff"/   

TableLayout  

android:id="@+id/table2"  

android:layout_width="fill_parent"  

android:layout_height="wrap_content"  

android:padding="3dip"  

TableRow  

Button android:text="第0列"/  

Button android:text="第1列"/  

Button android:text="第2列"/  

/TableRow  

TableRow  

TextView android:text="我被指定在第1列" android:layout_column="1"/  

/TableRow  

TableRow  

TextView  

android:text="我跨1到2列,不信你看!"  

android:layout_column="1"  

android:layout_span="2"  

/  

/TableRow  

/TableLayout

安卓表格控件怎么开发

Android 控件开发功底不错的话推荐使用自定义的DataGridView,当然一般的表格在GitHub上面是可以找到很多开源的DataGridView自定义控件源码的,可以尝试一下。如果对自定义控件开发不熟悉的话可以使用tableLayout或者是调用JavaScript

有没有类似于excel效果的Android表格编辑控件

android 里面有类似的软件应该是wps系列软件,他们可以实现编辑的功能。

Android 表格布局中 控件高度不一致问题问题

?xml version="1.0" encoding="utf-8"?

LinearLayout xmlns:android=""

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="你好" /

RadioButton

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_weight="5" /

/LinearLayout这个就可以解决你问题


新闻名称:android表格控件,Android 表格
标题路径:http://cdxtjz.cn/article/hoioej.html

其他资讯