android之网格布局和线性布局实现注册页面
(注意:1、再用weight的时候,各个组件要设置宽度为0dp,高度也要设置,2、即使没有设置weight,再用linear布局时,比如view和button都要设置宽度高度。3、如果出现运行错误,可以先检查哪个组件没设置高度)
:values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Day_02_07</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string-array name="citys">
<item>北京</item>
<item>天津</item>
<item>上海</item>
<item>重庆</item>
</string-array>
</resources>
主页面:
:layout/activity_main.xml
<LinearLayout 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"
android:orientation="vertical">
<Button
android:id="@+id/btn_linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="用线性布局实现注册"
android:onClick="linearLayout"/>
<Button
android:id="@+id/btn_relativelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="用相对布局实现注册"/>
<Button
android:id="@+id/btn_tablelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="用表格布局实现注册"/>
<Button
android:id="@+id/btn_Gridlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="用网格布局实现注册"
android:onClick="girdLayout"/>
</LinearLayout>
网格布局:
layout/grid_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:columnCount="5">
<TextView
android:text="用 户 名"/>
<EditText
android:hint="2-10个字符"
android:layout_columnSpan="4"
android:layout_gravity="fill_horizontal"/>
<TextView
android:text="输入密码"/>
<EditText
android:hint="2-10个字符"
android:layout_columnSpan="4"
android:password="true"
android:layout_gravity="fill_horizontal"/>
<TextView
android:text="确认密码"/>
<EditText
android:hint="2-10个字符"
android:layout_columnSpan="4"
android:password="true"
android:layout_gravity="fill_horizontal"/>
<TextView
android:layout_marginTop="10dp"
android:text="选择性别"/>
<RadioGroup
android:layout_marginLeft="10dp"
android:layout_columnSpan="4"
android:layout_gravity="fill_horizontal"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rbMale"
android:text="男"
android:checked="true"/>
<RadioButton
android:id="@+id/rbFemale"
android:text="女"/>
</RadioGroup>
<TextView
android:text="所在地"/>
<Spinner
android:layout_columnSpan="4"
android:entries="@array/citys"/>
<TextView
android:layout_marginTop="10dp"
android:text="选择爱好"/>
<RadioGroup
android:layout_columnSpan="4"
android:orientation="horizontal">
<CheckBox
android:text="读书"
android:checked="true"/>
<CheckBox
android:text="旅游"/>
<CheckBox
android:text="电玩"/>
</RadioGroup>
<Button
android:visibility="invisible"/>
<Button
android:text="注册"
android:textColor="#fff"
android:padding="3dp"
android:drawableLeft="@drawable/login32x32"
android:background="@drawable/btn_bg"/>
<Button
android:visibility="invisible"/>
<Button
android:text="退出"
android:textColor="#fff"
android:padding="3dp"
android:drawableLeft="@drawable/exit32x32"
android:background="@drawable/btn_bg"/>
<Button
android:visibility="invisible"/>
<Button
android:text="返回"
android:layout_gravity="bottom|fill_horizontal"
android:layout_columnSpan="5"
/>
</GridLayout>
效果:
线性布局
:layout/linear_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名:"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="请输入1-10个字符"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密 码:"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="请输入1-10个字符"
android:password="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确认密码:"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="请输入1-10个字符"
android:password="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="选择性别:"/>
<RadioGroup
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/rbMale"
android:text="男"
android:checked="true"/>
<RadioButton
android:id="@+id/rbreMale"
android:text="女"/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="城市:"/>
<Spinner android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="@array/citys"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="兴趣爱好:"/>
<RadioGroup
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<CheckBox
android:text="读书"
android:checked="true"/>
<CheckBox
android:text="旅游"
/>
<CheckBox
android:text="打电子"
/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_weight="1"
/>
<Button
android:id="@+id/btRegister"
android:text="注册"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/login32x32"
android:background="@drawable/btn_bg"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_weight="1"
/>
<Button
android:id="@+id/btEixt"
android:text="退出"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/exit32x32"
android:background="@drawable/btn_bg"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<Button
android:text="返回"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|fill_horizontal"
android:background="@drawable/btn_bg"
/>
</LinearLayout>
</LinearLayout>
效果:
java代码:
com.example.day_02_07.MainActivity
package com.example.day_02_07;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
//处理网格布局按钮的点击事件
public void girdLayout(View v){
Log.i("main",((Button)v).getText().toString());
setContentView(R.layout.grid_layout);
}
//处理线性布局按钮的点击事件
public void linearLayout(View v){
Log.i("main",((Button)v).getText().toString());
setContentView(R.layout.linear_layout);
}
}
主页效果:
相关推荐
本实验主要关注两种基本布局:线性布局(LinearLayout)和网格布局(GridLayout),并通过使用TextView标签来实现特定的视觉效果。 线性布局是Android中最基础的布局方式,它将组件沿着水平或垂直方向线性排列。在...
在Android应用开发中,页面布局是构建用户界面的关键部分,它定义了屏幕元素的排列方式、大小和相互关系。这个“android 中页面布局使用demo”应该是为了帮助开发者深入理解并实践Android中的各种布局管理器。下面...
简单的流程可以概括为:第一次进入页面,有个默认的布局(网格布局),点击按钮,由网格布局切换到竖直的线性布局,再次点击切换到网格布局。 分析: 可以看到商品展示的形式都是以列表的方式来展现,我用的是...
本文将详细介绍如何使用 Android 中的线性布局管理器(LinearLayout)实现微信登录页面的设计和开发。线性布局管理器是 Android 布局中的一个基本组件,它可以帮助开发者快速创建用户界面。 一、 Android 布局管理...
本篇文章将深入探讨四种主要的布局方式:线性布局、表格布局、相对布局和帧布局,以及如何进行布局嵌套。 首先,线性布局(LinearLayout)是最基础的布局方式,它可以将子视图按照垂直或水平方向线性排列。通过设置...
- **网格布局(GridLayout)**:将子视图组织成行和列的网格。通过`android:columnCount`和`android:rowCount`属性定义网格大小。 - **约束布局(ConstraintLayout)**:提供更灵活的布局,允许子视图根据相互关系...
在Android中,常见的布局管理器有线性布局(LinearLayout)、相对布局(RelativeLayout)、帧布局(FrameLayout)和网格布局(GridLayout)。对于登录注册页面,通常会选择线性布局或相对布局,因为它们能更好地控制...
本文对Android系统支持的布局进行了深入研究,并探讨了如何使用这些布局方法来设计和实现应用项目的主界面。 首先,Android应用程序主要由四大组件构成,包括Activity、Intent Receiver、Service和ContentProvider...
本篇文章将详细讲解Android的几种布局方式,包括线性布局、相对布局、表格布局、网格视图、标签布局、列表视图以及已废弃的绝对布局。 1. **线性布局(Linear Layout)** 线性布局是最基础的布局方式,它可以按照...
具有分页功能的 Recyclerview 布局管理器,主打分页,可以替代部分场景下的网格布局,线性布局,以及一些简单的ViewPager,但也有一定的局限性,请选择性使用。 网格分页布局源码解析(上) 网格分页布局源码解析(下)...
线性布局中的每个子视图默认会按照顺序依次放置,可以通过设置权重(`android:layout_weight`)来调整各个视图占据的空间比例。 2. **RelativeLayout(相对布局)**: 相对布局允许子视图根据彼此的位置进行排列,...
本资源“Android 注册界面源码.zip”包含了一个完整的注册界面项目,名为“Register_Project”,对于想要深入理解Android界面设计和实现的开发者来说,这是一个宝贵的参考资料。 在Android中,视图布局(View ...
2. **布局设计**:Android布局设计是构建UI的基础,包括线性布局(LinearLayout)、相对布局(RelativeLayout)、帧布局(FrameLayout)等。易信的UI布局可能会结合多种布局,以实现不同组件的精确对齐和动态交互。 ...
本压缩包“UI.rar”似乎包含了与Android UI设计相关的资源和示例,特别是涉及到不同的页面布局和交互元素。 首先,我们来深入理解Android UI的基础——布局(Layout)。布局在Android中是用来组织和控制屏幕上的...
本篇将详细讲解Android中的五种主要布局:线性布局(Linear Layout)、相对布局(Relative Layout)、表格布局(Table Layout)、网格布局(GridView)以及列表布局(ListView)。 1. **线性布局(Linear Layout)*...
4. **网格布局(GridLayout)**:网格布局将视图组织成行和列,非常适合创建图像画廊,用户可以快速浏览多张图片。 5. **表格布局(TableLayout)**:类似于HTML中的表格,可以用于呈现结构化数据,如电子书的目录...
在Android应用开发中,设计和实现一款类似360安全卫士的用户界面是一项挑战性的任务,因为它需要兼顾美观、易用性和功能性。本篇主要关注"360安全卫士"布局的设计与实现,我们将深入探讨如何创建这样一个布局,并...
Android主要使用XML来定义界面布局,常见的布局类型有线性布局(LinearLayout)、相对布局(RelativeLayout)、帧布局(FrameLayout)以及网格布局(GridLayout)。在这种情况下,我们可以使用TabLayout结合...
常见的布局类型有LinearLayout(线性布局)、RelativeLayout(相对布局)、FrameLayout(帧布局)和ConstraintLayout(约束布局)。自定义布局框架通常是基于这些基本布局进行扩展,添加特殊功能或优化性能。 在这...
本篇文章将深入探讨Android中的七种主要布局:线性布局(Linear Layout)、相对布局(Relative Layout)、表格布局(Table Layout)、网格视图(Grid View)、标签布局(Tab Layout)、列表视图(List View)以及...