首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

[android]控件TextView的惯用属性

2012-09-12 
[android]控件TextView的常用属性代码中常用属性:TextView tvnew TextView(Conext context)tv.setText(

[android]控件TextView的常用属性

代码中常用属性:

TextView tv=new TextView(Conext context);

tv.setText("这是一个控件");---设置控件上的文本内容

tv.setBackgroundColor(Color.WHITE);---设置背景颜色

tv.setTextColor(Color.BLACK);---设置控件上文本的颜色

tv.setTextSize(25);---设置控件上文本的大小

tv.setGrativity(Gravity.CENTER_VERTICAL);---设置文本内容相对于此控件的对齐方式

//设置TextView的布局参数     布局宽     布局高

LayoutParms params=new LayoutParams(480,300);

tv.setLayoutParms(params);


布局xml文件中常用属性:

android:layout_width=""---控件宽

android:layout_height=""---控件高

android:layout_weight=""---控件权重

android:text=""---控件上的文本内容

android:textColor=""---文本颜色

android:textSize=""---文本大小

android:layout_marginRight="5dp"---控件右边空出5dp的距离

android:backGround=""---控件的背景色

android:gravity=""---文本相对控件的位置

android:layout_gravity=""---控件相对于其所在容器的位置

android:layout_x="'---控件距父容器左上角的水平距离

android:layout_y=""---控件距父容器左上角的垂直距离

热点排行
Bad Request.