Andriod Studio基础界面设计

来源:互联网 发布:python宝典 pdf 编辑:程序博客网 时间:2024/06/10 08:31


来自移动应用开发的课程实验1,

要求设计出这样一个类似于如下的界面,从什么都不懂也学到了一点东西,主要是Android的布局和程序分开处理,有利于巴拉巴拉贝拉。。。

     

xml代码如下:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schema.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="com.example.administrator.myapplication.MainActivity">    <TableLayout        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_gravity="center_horizontal">        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="@string/sysu_title"            android:textSize="20sp"            android:layout_marginTop="@dimen/Twenty"            android:gravity="center" />    <ImageView        android:layout_marginTop="20dp"        android:src="@drawable/sysu"        android:layout_width="100dp"        android:layout_height="100dp" />    <TableRow        android:layout_marginTop="20dp"        android:layout_width="fill_parent"        android:layout_height="wrap_content">        <TextView            android:layout_marginLeft="20dp"            android:text="用户名"            android:textSize="18sp"            android:layout_width="wrap_content"            android:layout_height="wrap_content" />        <EditText            android:layout_marginRight="20dp"            android:textSize="18sp"            android:hint="请输入用户名"            android:layout_weight="1"            android:layout_width="0dp"            android:layout_height="wrap_content" />    </TableRow>    <TableRow        android:layout_marginTop="20dp"        android:layout_width="match_parent"        android:layout_height="wrap_content">        <TextView            android:layout_marginLeft="10dp"            android:text="密码"            android:gravity="right"            android:textSize="18sp"            android:layout_width="wrap_content"            android:layout_height="wrap_content" />        <EditText            android:layout_marginRight="20dp"            android:textSize="18sp"            android:hint="请输入密码"            android:layout_weight="1"            android:layout_height="wrap_content"            android:inputType="textPassword" />    </TableRow>    <RadioGroup        android:gravity="center_horizontal"        android:layout_marginTop="20dp"        android:orientation="horizontal"        android:layout_height="wrap_content"        android:layout_width="match_parent">        <RadioButton            android:textSize="18sp"            android:text="学生"            android:checked="true"            android:layout_width="wrap_content"            android:layout_height="wrap_content" />        <RadioButton            android:layout_marginLeft="10dp"            android:textSize="18sp"            android:text="老师"            android:layout_width="wrap_content"            android:layout_height="wrap_content" />        <RadioButton            android:layout_marginLeft="10dp"            android:textSize="18sp"            android:text="社团"            android:layout_width="wrap_content"            android:layout_height="wrap_content" />        <RadioButton            android:layout_marginLeft="10dp"            android:textSize="18sp"            android:text="管理者"            android:layout_width="wrap_content"            android:layout_height="wrap_content" />    </RadioGroup>    </TableLayout>    <TableLayout    android:layout_width="match_parent"    android:layout_height="wrap_content">    <TableRow        android:gravity="center_horizontal"        android:layout_marginTop="20dp"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="horizontal">        <Button            style="@style/My_button"            android:textColor="#FFFFFF"            android:layout_marginLeft="5dp"            android:text="登陆" />        <Button            android:layout_marginLeft="25dp"            android:background="@drawable/shape"            android:textColor="@color/primary_black"            android:text="注册"            android:textSize="18sp"            android:layout_width="wrap_content"            android:layout_height="wrap_content" />    </TableRow>    </TableLayout></LinearLayout>
学到一些知识点:

<LinearLayout>:线性版面配置,在这个标签中,所有元件都是按由上到下的排列组成,其他布局可类比。
Orientation 表示版面配置方式
Layout_width:定义当前视图在屏幕上所占的宽度,fill_parent填充整个屏幕,match_parent即和父类的宽度相等
Wrap_content:随着文字栏位的不同而改变这个视图的宽度或高度
Gravity表示居中等样式
RadioGroup中的Radiobutton表示选择框

0 0