Android UI控件系列:TextView(文本框)

黄舟
发布: 2017-01-19 09:24:31
原创
1396人浏览过

textview比较简单,不能够用来进行编辑,只能够用来显示信息

布局文件里的一些常用的xml属性

android:gravity—用来设置控件内文本的对齐方式

android:layout_gravity—相对于父控件来说,用于设置控件的对齐方式

android:text—用来设置控件文本信息

android:layout_width—用来设置控件的宽度

android:layout_height—用来设置控件的高度

android:background—用来设置控件的背景色

android:textcolor—用来设置控件内文本的颜色

android:textsize—用来设置控件的文本字体大小

android:width和android:height—功能与android:layout_width相似

区别:

android:layout_width只能设置fill_parent(横向填充整个屏幕)或
wrap_content(横向填充控件本身大小)

android:width设置具体控件的横向大小 单位是像素
例如:textview显示

main.xml布局文件

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:orientation="vertical"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
    >  
<TextView  
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content"  
    android:text="@string/hello"  
    />  
</LinearLayout>
登录后复制

string.xml文件

<?xml version="1.0" encoding="utf-8"?>  
<resources>  
    <string name="hello">Hello World, MyTestView!</string>  
    <string name="app_name">MyTestView</string>  
</resources>
登录后复制

MyTextView.java文件

package org.loulijun.MyTestView;  
  
import android.app.Activity;  
import android.os.Bundle;  
  
public class MyTestView extends Activity {  
    /** Called when the activity is first created. */  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
    }  
}
登录后复制

运行结果:

序列猴子开放平台
序列猴子开放平台

具有长序列、多模态、单模型、大数据等特点的超大规模语言模型

序列猴子开放平台 0
查看详情 序列猴子开放平台

373.gif

以上就是Android UI控件系列:TextView(文本框)的内容,更多相关内容请关注PHP中文网(www.php.cn)!

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号