简介
View视图是构建用户界面的基础组件。它是屏幕上的一块矩形区域,负责绘制和响应用户交互。在Android应用开发中具有广泛的应用场景和重要的作用。通过合理使用和定制View视图,开发者可以创建出功能丰富、界面美观、性能出色的Android应用。
一、view的xml布局
view单一布局
<View
android:id="@+id/view"
android:layout_width="320dp"
android:layout_height="290dp"
android:layout_marginStart="52dp"
android:layout_marginTop="368dp"
android:background="@drawable/view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</View>
view应用布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:id="@+id/main"
android:background="#B9E6D6"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<View
android:id="@+id/view"
android:layout_width="320dp"
android:layout_height="290dp"
android:layout_marginStart="52dp"
android:layout_marginTop="368dp"
android:background="@drawable/view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</View>
<EditText
android:id="@+id/zh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:ems="10"
android:hint="账号:"
android:inputType="text"
app:layout_constraintEnd_toEndOf="@+id/view"
app:layout_constraintStart_toStartOf="@+id/view"
app:layout_constraintTop_toTopOf="@+id/view" />
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:ems="10"
android:hint="密码:"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="@+id/view"
app:layout_constraintStart_toStartOf="@+id/view"
app:layout_constraintTop_toBottomOf="@+id/zh" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="登录"
app:layout_constraintEnd_toEndOf="@+id/view"
app:layout_constraintStart_toStartOf="@+id/view"
app:layout_constraintTop_toBottomOf="@+id/password" />
</androidx.constraintlayout.widget.ConstraintLayout>
二、创建一个xml文件在drawable中
三、view.xml简要内容
android:shape这个属性表示图像的形状,可以是rectangle(矩形)、oval(椭圆)、line(横线)、ring(圆环)。默认为rectangle。这里对于ring值还有几个相关的属性:
<corners>指定边角的半径,数值越大角越圆,数值越小越趋近于直角,radius直接指定4个角的半径,其它4个属性则单独设置4个角的角度,相关属性如下:
<solid>纯色填充,通过android:color设置颜色。
四、最终效果