您的位置:首页 > 产品设计 > UI/UE

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

2017-10-02 16:05 721 查看
TextView和EditText

常用属性:

android:id---控件的id
android: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"/>


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: