Android学习-常见的UI控件 TextView、EditText和ImageView

来源:互联网 发布:淘宝卖家回复差评用语 编辑:程序博客网 时间:2024/05/16 08:22

TextView和EditText

常用属性:

android:id---控件的idandroid:layout_width---控件的宽度android:layout_height---控件的高度android:text---文本内容android:textSize---文本大小android:textColor---文本颜色android:background--空间背景

EditText特有:

android:hint---输入提示文本android:inputType---输入类型
<!-- wrap_content:包裹实际文本内容        match_parent:当前控件铺满父类容器 2.3api之后添加的属性值        fill_parent:当前控件铺满父类容器  2.3api之前的属性值        android:orientation="vertical"各控件竖直排布    -->    <TextView        android:id="@+id/textView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="姓名:"        android:textSize="28sp"        android:textColor="#000000"        />    <EditText        android:id="@+id/editText1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:hint="请输入你的姓名"        />

再将布局文件引入到acitivity中来

public class FirstActivity extends AppCompatActivity {    private static final String TAG = "FirstActivity";    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        //将布局xml文件引入到activity中来        setContentView(R.layout.first_layout);    }}

注册活动

<manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.angel.activity">    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:roundIcon="@mipmap/ic_launcher_round"        android:supportsRtl="true"        android:theme="@style/AppTheme">        <activity android:name=".FirstActivity">          <intent-filter>              <action android:name="android.intent.action.MAIN"/>              <category android:name="android.intent.category.LAUNCHER"/>          </intent-filter>        </activity>    </application></manifest>

运行结果
这里写图片描述

ImageView

1.什么是ImageView

  表示图片的一个控件

2.ImageView属性

 android:src="@drawable/ic_launcher"---ImageView的内容图像   android:background="@drawable/ic_launcher"---ImageView的背景图片   android:background:"#00ff00"---ImageView的RGB颜色 

ImageView的android:src和android:background 都可以引入图片,但是当宽度调成match_parent的时候后者江湖等比例拉伸

background同时也可以设置背景色
在imageView3中因为如果高度设置成wrap_content的话看不到颜色,因为该控件中没内容,所以没有高度,因此我们手动设置高度为10dp

<ImageView        android:id="@+id/imageView1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:src="@mipmap/ic_launcher" />    <ImageView        android:id="@+id/imageView2"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:background="@mipmap/ic_launcher" />    <ImageView        android:id="@+id/imageiew3"        android:layout_width="match_parent"        android:layout_height="10dp"        android:background="#00ff00"/>

这里写图片描述

阅读全文
1 0
原创粉丝点击