Android常用UI组件 - TextView

TextView是Android里面用的最多的UI组件,一般使用在需要显示一些信息的时候,其不能输入,只能初始设定或者在程序中修改。

实例:TextViewDemo
运行效果:

代码清单:
布局文件: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="这里是TextView,你可以在这里显示一些文本信息。"
    />
</LinearLayout>
Java源代码文件:MainActivity.java
package com.rainsong.textviewdemo;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}


API知识点
Activity
public class
Activity
extends ContextThemeWrapper
implements ComponentCallbacks2 KeyEvent.Callback LayoutInflater.Factory2 View.OnCreateContextMenuListener Window.Callback

Known Direct Subclasses
AccountAuthenticatorActivity, ActivityGroup, AliasActivity, ExpandableListActivity, FragmentActivity, ListActivity, NativeActivity

Known Indirect Subclasses
LauncherActivity, PreferenceActivity, TabActivity

void setContentView(int layoutResID)
Set the activity content from a layout resource.

TextView
public class
TextView
extends View
implements ViewTreeObserver.OnPreDrawListener

Known Direct Subclasses
Button, CheckedTextView, Chronometer, DigitalClock, EditText, TextClock

Known Indirect Subclasses
AutoCompleteTextView, CheckBox, CompoundButton, ExtractEditText, MultiAutoCompleteTextView, RadioButton, Switch, ToggleButton

Class Overview
Displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing; see EditText for a subclass that configures the text view for editing.

Public Constructors
TextView(Context context)
TextView(Context context, AttributeSet attrs)
TextView(Context context, AttributeSet attrs, int defStyle)

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。