美文网首页
控件 - TextView

控件 - TextView

作者: C_G__ | 来源:发表于2019-04-24 09:47 被阅读0次

TextView 文本域

显示文本信息

属性

  • android:id:ID,唯一标识符。
  • android:layout_width:宽。
    match_parent:当前控件大小和父控件一样。
    wrap_content:当前控件大小刚好包含里边内容。
  • android:layout_height:高,同上。
  • android:text:文本信息。
  • android:textSize:文本字号。
  • android:textColor:文本颜色。
  • android:gravity:文字对齐方式,可用 | 指定多个值
    top:顶对齐
    bottom:底对齐
    left:左对齐
    right:右对齐
    center:居中
  • android:shadowColor:阴影颜色。
  • android:shadowRadius:阴影半径。
  • android:shadowDy:阴影纵轴向偏移。
  • android:shadowDx:阴影横轴偏移。

代码示例

activity_com_text_view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".chapter03.TextViewActivity"
    android:orientation="vertical">

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tv_textview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="This is a TextView!"
                android:textSize="24sp"
                android:textColor="#ccffff"
                android:gravity="center"
                android:shadowColor="#000000"
                android:shadowRadius="5"
                android:shadowDy="3"
                android:shadowDx="3"/>

        </LinearLayout>
    </ScrollView>

</LinearLayout>

TextViewActivity.java

public class TextViewActivity extends MyBaseActivity {

    TextView mTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_com_text_view);

        mTextView = findViewById(R.id.tv_textview);
        mTextView .setText("This is a TextView");
    }

}

相关文章

网友评论

      本文标题:控件 - TextView

      本文链接:https://www.haomeiwen.com/subject/nujbgqtx.html