android布局

Android布局详解之一:FrameLayout

早过忘川 提交于 2019-11-29 12:36:18
原创文章,如有转载,请注明出处: http://blog.csdn.net/yihui823/article/details/6702273 FrameLayout是最简单的布局了。所有放在布局里的控件,都按照层次堆叠在屏幕的左上角。后加进来的控件覆盖前面的控件。 在FrameLayout布局里,定义任何空间的位置相关的属性都毫无意义。控件自动的堆放在左上角,根本不听你的控制。 看以下的例子: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="50dip" android:textColor="#ffffff" android:text="第一层"/> <TextView android:layout_width="fill_parent" android:layout

android:TableLayout表格布局详解

末鹿安然 提交于 2019-11-29 12:36:06
这篇博文包括的内容: 1、TableLayout简介 2、 TableLayout行列数的确定 3、 TableLayout可设置的属性详解 4、一个包含4个TableLayout布局的实例及效果图 一、Tablelayout简介 Tablelayout类以行和列的形式对控件进行管理,每一行为一个TableRow对象,或一个View控件。 当为TableRow对象时,可在TableRow下添加子控件,默认情况下,每个子控件占据一列。 当为View时,该View将独占一行。 二、TableLayout行列数的确定 TableLayout的行数由开发人员直接指定,即有多少个TableRow对象(或View控件),就有多少行。 TableLayout的列数等于含有最多子控件的TableRow的列数。如第一TableRow含2个子控件,第二个TableRow含3个,第三个TableRow含4个,那么该TableLayout的列数为4. 三、TableLayout可设置的属性详解 TableLayout可设置的属性包括全局属性及单元格属性。 1、全局属性也即列属性,有以下3个参数: android:stretchColumns 设置可伸展的列。该列可以向行方向伸展,最多可占据一整行。 android:shrinkColumns 设置可收缩的列。当该列子控件的内容太多,已经挤满所在行

自定义布局View

≡放荡痞女 提交于 2019-11-29 11:43:32
引入布局 如果你用过 iPhone 应该会知道, 几乎每一个 iPhone应用的界面顶部都会有一个标题栏, 标题栏上会有一到两个按钮可用于返回或其他操作(iPhone 没有实体返回键) 。现在很多的 Android程序也都喜欢模仿 iPhone的风格,在界面的顶部放置一个标题栏。虽然 Android系 统已经给每个活动提供了标题栏功能,但这里我们仍然决定不使用它,而是创建一个自定义 的标题栏。 经过前面两节的学习,我想创建一个标题栏布局对你来说已经不是什么困难的事情了, 只需要加入两个 Button 和一个 TextView,然后在布局中摆放好就可以了。可是这样做却存 在着一个问题,一般我们的程序中可能有很多个活动都需要这样的标题栏,如果在每个活动 的布局中都编写一遍同样的标题栏代码,明显就会导致代码的大量重复。这个时候我们就可 以使用引入布局的方式来解决这个问题,新建一个布局 title.xml,代码如下所示: <LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" android: layout_width= "match_parent" android: layout_height= "wrap_content" android: background= "@drawable

[Android开发]LinearLayout与RelativeLayout异同深入探讨

﹥>﹥吖頭↗ 提交于 2019-11-29 10:53:54
Android初级工程师或者校招的面试过程中,很容易被问到LinearLayout与RelativeLayout区别,这是一个基础问题,由此可以引出例如ViewGroup和View绘制流程等问题,可以看出应聘者的掌握程度。 一般可以这么回答回答: LinearLayout为线性布局: 1. 分为垂直布局(vertical)和水平布局(horizontal)两种(android:orientation属性) 2. 可以通过设置控件的android:layout_weight属性以控制各个控件在布局中的相对大小,线性布局会根据该控件layout_weight值与其所处布局中所有控件layout_weight值之和的比值为该控件分配占用的区域。如果layout_weight指为0,控件会按原大小显示,不会被拉伸;对于其余layout_weight属性值大于0的控件,系统将会减去layout_weight属性值为0的控件的宽度或者高度,再用剩余的宽度或高度按相应的比例来分配每一个控件显示的宽度或高度。 3. android:baselineAligned,默认为true,即基准线对其。另外还有android:baselineAlignedChildIndex用于指定以哪个child为基准。 RelativeLayout为相对布局: 1. 允许子元素指定它们相对于其父元素或兄弟元素的位置

Android 宿舍成员小案例

心不动则不痛 提交于 2019-11-29 03:32:34
成功的买到了这本叫做课本的书之后 我想到了一个案例 打算自己来做一做 目的是储存班级的每一个人的基本信息 相比于之前的文章来说 这个新的案例,在外部看起来没有什么和之前的有什么比较特别的地方 但是实现代码上来说, 我尝试了很多不同的方法来实现基本同样的功能 通过调试,检测每一个控件的属性, 属性没有研究到的大概就是不太常用的, 在以后会慢慢的补充, 还有百度真是个好东西哈哈哈哈 首先对我的程序框架进行介绍, 我使用了10个activity,每个activity代表了一个界面的代码 在看下面的界面和逻辑之前需要先看一下AndroidManifest 下面的“//”实际上是用来我自己看的,要是真的想注释的话,使用ctrl+shift+/ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" //叫什么命名空间下载地址的 package="com.example.xialm.myapplication"> <application android:allowBackup="true" //是否允许返回操作 android:icon="@mipmap/ic_launcher" //图标使用什么 android:label="

网格布局 GridLayout

♀尐吖头ヾ 提交于 2019-11-28 20:13:57
网格布局,按照行、列组成一个个网格 界面代码: <?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:rowCount="6" android:columnCount="4" android:id="@+id/root" tools:context=".MainActivity"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_columnSpan="4" android:textSize="50sp" android:layout_marginLeft="2pt" android:layout_marginRight

Android ——TabHost使用

℡╲_俬逩灬. 提交于 2019-11-28 18:56:24
在Android中,通常可以使用切换卡(选项卡)实现切换显示不同页面内容的功能。这一功能可以通过TabHost控件来实现。   下面我们就通过一个简单的实例演示如何使用TabHost控件完成切换卡功能,完成后的运行效果如图1所示。 图1 主页显示效果   可以看出,在该实例中,总共设置了四个TabHost标签,分别为主页、时间、联系人和搜索。在点击这些标签时,便可以完成相应页面内容的显示。 1.界面布局   TabHost是整个Tab的容器,是由TabWidget和FrameLayout 两部分组成的。其中,TabWidget是每个tab的标签,而FrameLayout则是tab所要显示的内容。   根据以上的描述,我们就可以对整个显示界面进行合理的布局了。我们以LinearLayout的垂直布局方式将整个TabHost分成上下两部分,上面使用TabWidget控件显示标签,下面使用FrameLayout布局显示每个标签下的对应内容。   具体的xml布局文件源码如下: <?xml version="1.0" encoding="utf-8"?>   <TabHost xmlns:android=" http://schemas.android.com/apk/res/android "    android:id=" @android :id/tabhost"   

android RecyclerView的Grid布局案例

荒凉一梦 提交于 2019-11-28 12:54:07
1、先创建activity_grid.xml 和 activity_grid_item.xml <?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:layout_width="match_parent" android:layout_height="match_parent" tools:context=".GridActivity"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/rv2" android:layout_width="match_parent" android:layout_height="match_parent" tools:layout_editor_absoluteX="103dp" tools:layout_editor

Android常规布局方式和方法

[亡魂溺海] 提交于 2019-11-28 12:21:16
一、关于给控件添加ID属性 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <include android:id="@+id/top" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" layout="@layout/top" /> <Button android:id="@+id/wifi_test_bnt" style="@style/CommonButtonStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/top" android:text="@string

ConstraintLayout布局学习

末鹿安然 提交于 2019-11-28 03:18:05
这两天跟着Google的官方文档学习了一下ConstraintLayout布局,相较于RelativeLayout来说最大的好处是ConstrainLayout布局可以减少嵌套,提升性能。 参考: 解析ConstraintLayout的性能优势 https://mp.weixin.qq.com/s/gGR2itbY7hh9fo61SxaMQQ? 相对定位 ConstraintLayout使用了相对定位,通过和父控件和其他控件来约束控件。   app:layout_constraintLeft_toLeftOf:控件左边相对于其他控件左边的约束   app:layout_constraintLeft_toRightOf:控件左边相对于其他控件右边的约束   app:layout_constraintRight_toLeftOf:控件右边相对于其他控件左边的约束   app:layout_constraintRight_toRightOf:控件右边相对于其他控件的右边的约束   app:layout_constraintTop_toTopOf   app:layout_constraintTop_toBottomOf   app:layout_constraintBottom_toTopOf    app:layout_constraintBottom_toBottomOf   app