android布局

Android 布局中的include标签使用

廉价感情. 提交于 2019-11-27 01:55:22
Android 布局中的include标签使用 最近在布局时,有好多页面都是有共同特点的,比如标题:一个同样的样式! 如下图所示: 如果给每个页面都单独的写一个标题的布局那就太麻烦了,如果能写一个标题布局,其它页面重用该多好! 这个时候, <include> 就隆重登场了! 写一个标题的布局 title.xml : <?xml version="1.0" encoding="utf-8"?> < RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:layout_width = "match_parent" android:layout_height = "wrap_content" android:background = "@drawable/navigation_bar" > < ImageView android:id = "@+id/img_backward" android:layout_alignParentLeft = "true" android:layout_centerVertical = "true" android:layout_marginLeft = "25dp" android:layout_gravity = "center"

Android 布局学习

旧巷老猫 提交于 2019-11-27 01:55:07
ViewGroup Width/Height , Padding/margin FrameLayout gravity LinearLayout Orientation/horizontal/vertical weight RelativeLayout alignBaseline/(Left/Top/Right/Bottom) Start/End alignParent center Horizontal/Vertical/InParent below/above/toLeftOf/toRightOf/toStartOf/toEndOf LinearLayout代码设置weight LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f); linearLayout.setLayoutParams(lp); Android布局优化 (非常好的一篇文章) http://www.infoq.com/cn/articles/android-optimise-layout selector几种状态 state_pressed state_focused state_selected TextView常用属性

Android的布局复用与优化

可紊 提交于 2019-11-27 01:53:39
在布局优化中,Android的官方提到了这三种布局<include />、<merge />、<ViewStub />,并介绍了这三种布局各有的优势,下面也是简单说一下怎么使用. 1、布局重用<include /> <include />标签能够重用布局文件,简单的使用如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width=”match_parent” android:layout_height=”match_parent” android:background="@color/app_bg" android:gravity="center_horizontal"> <include layout="@layout/layout_title"/> <TextView android:layout_width=”match_parent” android:layout_height="wrap_content" android:text="@string/hello" android:padding="10dp" /> ... </LinearLayout> 1)<include /

Android_studio布局

大兔子大兔子 提交于 2019-11-27 01:49:41
Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):按照垂直或者水平方向布局的组件。 帧布局(FrameLayout):组件从屏幕左上方布局组件。 表格布局(TableLayout):按照行列方式布局组件。 相对布局(RelativeLayout):相对其它组件的布局方式。 绝对布局(AbsoluteLayout):按照绝对坐标来布局组件。 1. 线性布局 线性布局是 Android 开发中最常见的一种布局方式,它是按照垂直或者水平方向来布局,通过 “android:orientation” 属性可以设置线性布局的方向。属性值有垂直( vertical )和水平( horizontal )两种。 常用的属性: android:orientation:可以设置布局的方向 android:gravity:用来控制组件的对齐方式 layout_weight:控制各个组件在布局中的相对大小 布局结果如下: 原代码如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app=

android约束布局

喜你入骨 提交于 2019-11-27 01:49:24
约束布局是谷歌在 使用: 为什么要使用约束布局: ConstraintLayout还有一个优点,它可以有效地解决布局嵌套过多的问题。 实现的布局效果类似于相对布局但比相对布局性能更高。 盗个别人对比的图: 从图中我们可以看出性能上约束布局比相对布局性能要好上40%左右,因此有这么好的布局方式为什么不用呢。 使用方式: 1.在项目中添加依赖: dependencies { compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1' } 2.布局中使用: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <!--子控件--> </android.support.constraint.ConstraintLayout> 实现子控件完全居中效果: <?xml version="1.0" encoding="utf-8"?>

android 重叠view 重叠布局

情到浓时终转凉″ 提交于 2019-11-27 01:38:25
使用RelativeLayout即可实现重叠布局——RelativeLayout标签内容里面的 下层布局会浮现在上层布局之上;上层布局会被下层布局覆盖 实现layout: <RelativeLayout android:layout_width="match_parent" android:layout_height="200dp" android:background="#FFE4C4"> <LinearLayout android:layout_width="300dp" android:layout_height="100dp" android:background="#303F9F"></LinearLayout> <LinearLayout android:layout_width="200dp" android:layout_height="100dp" android:background="#FF4081" android:layout_marginLeft="50dp" android:layout_marginTop="50dp"></LinearLayout> </RelativeLayout> 实现效果: 来源: CSDN 作者: meixi_android&java 链接: https://blog.csdn.net/meixi_android

android LinearLayout布局嵌套覆盖问题

旧时模样 提交于 2019-11-27 01:37:44
在做android UI布局时,用了LinearLayout嵌套,发现效果并不如我预料一般 查了下资料,说是要设置layout_weight属性 资料说得不是很清楚,也没仔细看,就去弄,结果越弄越混乱。 于是静下心来,自己写xml测试,发现如下。 我用eclipse开发,用android Common XML Editor 使用快捷键alt+/ 一、如果LinearLayout是最外面的一层,它是不会弹出layout_weight属性的 换句话说最外层不能用layout_weight 二、xml布局如下 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content"

android 相对布局覆盖问题

坚强是说给别人听的谎言 提交于 2019-11-27 01:37:33
线性布局下有两个相对布局 当第一个相对布局如下: <RelativeLayout android:id="@+id/silentLayout" android:layout_width="match_parent" android:layout_height="40dp" android:orientation="vertical" > 当 android:layout_height="40dp" 变为 android:layout_height="match_parent" 的时候第二个线性布局就会被第一个线性布局覆盖。 来源: CSDN 作者: 玄冥之巅 链接: https://blog.csdn.net/kingda008/article/details/7911200

使用viewstub实现嵌套布局

泄露秘密 提交于 2019-11-27 00:34:16
Viewstub的使用是比较简单的。他就仿佛是个layout。然后把其他的布局文件看作是一个view标签 然后把这些view标签往这个layout中填充, 当然 这个layout也可以有自己的布局方式 所以我把他理解成为嵌套布局。 源码下载地址: http://zhengxdstudy.googlecode.com/svn/trunk/zhengxdstudy/viewstub 效果图 viewstub布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=" http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ViewStub android:id = "@+id/stub_import" android:inflatedId = "@+id/panel_import" android:layout = "@layout/index" 指定index.xml布局文件 android:layout_width = "fill_parent"

Android——layout_marginStart和layout_marginEnd的详细讲解

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 00:14:00
8.4.6 从右到左布局(RTL Layout) 从Android 4.2开始,Android SDK支持一种从右到左(RTL,Right-to-Left)UI布局的方式,尽管这种布局方式经常被使用在诸如阿拉伯语、希伯来语等环境中,中国用户很少使用。不过在某些特殊用途中还是很方便的。 所谓RTL,就是指按平常习惯在左的视图都会在右侧,在右侧的视图都会在左侧。例如,在线性布局中第1个子视图默认都是在左上角的,如果采用RTL布局,默认就在右上角了。 RTL布局默认是关闭的,如果想使用RTL布局,首先要在AndroidManifest.xml文件中将<application>标签的android:supportsRtl属性值设为"true",然后需要将相应视图标签的android:layoutDirection属性值设为"rtl"。 如果要使用RTL布局,还应该注意一个重要的问题。假设一个水平线性布局中有两个<TextView>标签:TextView1和TextView2。TextView1位于窗口的左上角,而TextVew2在TextView1的右侧,到TextView1的距离是100dp。实际上就是TextView2的左边缘到TextView1的右边缘的距离。如果当前是默认布局方式(LTR,从左到右,Left-to-Right),只需要将TextView2的android