Android UI control series: TextView (text box)

黄舟
Release: 2023-03-04 22:54:02
Original
1223 people have browsed it

TextView is relatively simple and cannot be used for editing. It can only be used to display information.

Some commonly used XML attributes in layout files

android:gravity—used to set the content of the control. Alignment of text

android:layout_gravity—used to set the alignment of the control relative to the parent control

android:text—used to set the text information of the control

android:layout_width—used to set the width of the control

android:layout_height—used to set the height of the control

android:background—used to set the background color of the control

android :textColor—used to set the color of the text in the control

android:textSize—used to set the text font size of the control

android:width and android:height—functions similar to android:layout_width

Difference:

android:layout_width can only set fill_parent (fill the entire screen horizontally) or
wrap_content (fill the size of the control itself horizontally)

android:width sets specific controls The horizontal size unit is pixels
For example: TextView display

main.xml layout file

<?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>
Copy after login

string.xml file

<?xml version="1.0" encoding="utf-8"?>  
<resources>  
    <string name="hello">Hello World, MyTestView!</string>  
    <string name="app_name">MyTestView</string>  
</resources>
Copy after login

MyTextView.java file

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);  
    }  
}
Copy after login

Running results:

Android UI control series: TextView (text box)

The above is the content of the Android UI control series: TextView (text box). For more related content, please pay attention to PHP Chinese Net (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template