目录
- 一、4种基础控件
- 二、padding和margin
- 三、制作一个登录界面
一、4种基础控件
- Button 按键
- TextView 文本框
- EditText 输入框
- ImageView 图片,带边框的
<ImageButton android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/bx2"/>
二、padding和margin
图大小不变,内外边框拉升
- margin 外边框,上下左右
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
- padding 文字和内边框距离
android:paddingTop="70dp"
android:paddingLeft="60dp"
android:paddingRight="60dp"
三、制作一个登录界面
每个控件设置:id,长宽,对齐,文本
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity" ><ImageButton android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/bx2"android:paddingTop="70dp"android:paddingLeft="60dp"android:paddingRight="60dp"android:layout_marginLeft="4dp"/><RelativeLayout android:layout_width="350dp"android:layout_height="130dp"android:layout_centerInParent="true"android:background="#ff0000"><TextView android:id="@+id/te1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginRight="10dp"android:layout_marginLeft="10dp"android:layout_marginTop="10dp"android:text="用户"android:textSize="20dp"android:background="#ffffff"/><EditText android:id="@+id/ed1"android:layout_width="280dp"android:layout_height="33dp"android:layout_marginTop="10dp"android:layout_toRightOf="@id/te1"/><TextView android:id="@+id/te2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@id/te1"android:textSize="20dp"android:layout_marginRight="10dp"android:layout_marginLeft="10dp"android:layout_marginTop="10dp"android:textColor="#ffffff"android:text="密码"/><EditText android:id="@+id/ed2"android:layout_width="280dp"android:layout_height="33dp"android:layout_toRightOf="@id/te2"android:layout_below="@id/ed1"/><Button android:id="@+id/aj1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@id/ed2"android:layout_alignRight="@id/ed2"android:layout_marginRight="20dp"android:text="取消"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_toLeftOf="@id/aj1"android:layout_alignBottom="@id/aj1"android:layout_marginRight="20dp"android:text="确定"/></RelativeLayout></RelativeLayout>
师承上官可编程 —— 陈立臣