android layout_gravity 和 android gravity 的区别
Android组件---四大布局的属性详解

Android组件---四⼤布局的属性详解【声明】欢迎转载,但请保留⽂章原始出处→_→Android常见布局有下⾯⼏种:LinearLayout:线性布局。
所有的控件都是串在⼀条线上的。
RelativeLayout:相对布局。
所有的控件的位置,都是相对于⽗控件的。
FrameLayout:帧布局。
FrameLayout布局中的控件都是⼀层⼀层的。
帧布局每次添加的控件都显⽰在最上⾯,最后显⽰在界⾯上的是最后添加的⼀个控件。
TableLayout:表格布局。
表格布局可以实现的.⼀般可以使⽤线性布局实现。
AbsoluteLayout:绝对布局。
已经是废弃的状态,很少⽤了。
orientation:属性是指定线性布局的排列⽅向。
horizontal ⽔平。
线性布局默认的朝向是⽔平的。
vertical 垂直例如:android:orientation="vertical"gravity:指定当前控件⾥⾯的内容容显⽰位置。
(四⼤layout中均可使⽤)left 左边right 右边top 上边bottom 底边例如:android:gravity="center"gravity中的属性可以组合使⽤。
例如:android:gravity="bottom|right"layout_gravity:指定当前控件在⽗元素的位置。
(只在 LinearLayout 和 FrameLayout 中有效)left 左边right 右边top 上边bottom 底边centercenter_horizontalcenter_vertical例如:android:layout_gravity="center"另外,需要提⽰的是,对于 LinearLayout :当 android:orientation="vertical" 时,只有⽔平⽅向的设置才起作⽤,垂直⽅向的设置不起作⽤。
Android Tips---Android平台常见属性集合

android:phoneNumber
true/false
设置为电话号码的输入方式。
android:privateImeOptions
提供额外的输入法选项(字符串格式)。
android:scrollHorizontally
true/false
设置文本超出TextView的宽度的情况下,是否出现横拉条。
android:fadingEdgeLength
设置边框渐变的长度。
android:linksClickable
设置链接是否点击连接,即使设置了autoLink
android:maxLines
设置文本的最大显示行数,与width或者layout_width结合使用,超出部分自动换行,超出行数将不显示
android:minLines
设置文本的最小行数
android:lineSpacingExtra
android:longClickable
true/false
view是否可以对长时间的click事件作出反应。
android:focusable
view是否能响应焦点事件
android:cacheColorHint
#00000000
滚动时,列表里面的view重绘时,用的依旧是系统默认的透明色,颜色值为#FF191919,要改变这种情况,只需要调用listView的setCacheColorHint(0),颜色值设置为0或者xml文件中listView的属性Android:cacheColorHint="#00000000"即可,滚动时,重绘View的时候就不会有背景颜色。
android:cursorVisible
true/false
安卓期末考试知识总结

安卓期末考试知识总结第一章:Android基础入门习题总结1.Android系统采用分层架构,由高到低分为4层,主要为:应用程序层、应用程序框架层、核心类库、Linux内核2.在Android项目程序开发完成后中,必须__打包成_正式的Android安装文件,才能发布到互联网上让用户下载使用。
3.Android 工程中src目录下存放_java__文件重点知识1.应用层:应用层是核心应用程序的集合。
手机上所有的应用都属于这一层,程序,短信程序。
2.应用程序框架层:应用程序框架层主要提供构建应用程序时用到的各种API,例如:活动管理器、通知管理器、内容提供者3.核心类库:核心类库中包含了系统库及Android运行环境。
(1)系统库主要通过c/c++库为Android系统提供主要的特性支持(2)Android运行时库主要提供一些核心库,允许开发者使用java语言来编写Android应用程序4.Linux内核:为Android·设备的各种硬件提供底层的驱动,如显示驱动、音频驱动、蓝牙驱动、电源管理驱动Android工程中的assets目录主要存放一些文件资源,这些文件会被原封不动的打包到APK文件中更为细分的5层架构:应用程序层、应用程序框架层、核心类库、硬件抽象层 (HAL)、Linux内核硬件抽象层 (HAL) 提供标准界面,向更高级别的 Java API 框架显示设备硬件功能。
HAL 包含多个库模块,其中每个模块都为特定类型的硬件组件实现一个界面,例如相机或蓝牙模块。
当框架 API 要求访问设备硬件时,Android 系统将为该硬件组件加载库模块。
第二章:Android常见桌面布局&第三章:Android常见界面控件知识总结1.Android应用的界面是由View 对象和 ViewGroup 对象构建而成的。
ViewGroup继承自View,ViewGroup作为容器盛装界面中的其他控件Android应用的每个界面的根元素必须有且只有一个ViewGroup容器Android常见布局和特点:Android中常见的五种布局:相对布局(RelativeLayout)、线性布局(LinearLayout)、表格布局(TableLayout)、帧布局(FrameLayout)、约束布局(ConstraintLayout)1.相对布局(RelativeLayout):相对布局是一种基于相对位置的布局方式,可以通过设置组件相对于其他组件或父容器的位置来实现布局。
Android开发自学笔记(AndroidStudio)—4.1布局组件

Android开发⾃学笔记(AndroidStudio)—4.1布局组件⼀、引⾔Android的界⾯是有布局和组件协同完成的,布局好⽐是建筑⾥的框架,⽽组件则相当于建筑⾥的砖⽡。
组件按照布局的要求依次排列,就组成了⽤户所看见的界⾯。
在Android4.0之前,我们通常说Android开发五⼤布局和四⼤组件,这五⼤布局就是:1. LinearLayout 线性布局2. FrameLayout 单帧布局,也有中⽂翻译为帧布局、框架布局。
3. RelativeLayout 相对布局4. AbsoluteLayout 绝对布局5. TableLayout 表格布局⽽在Android4.0之后⼜新增了⼀种GridLayout⽹格布局。
⼆、LinearLayout线性布局线性布局是Android开发中最常见的⼀种布局⽅式,它是按照垂直或者⽔平⽅向来布局,通过“android:orientation”属性可以设置线性布局的⽅向。
属性值有垂直(vertical)和⽔平(horizontal)两种。
线性布局的排列在某⾏或者某列并不会⾃动换⾏或换列,就是说如果采⽤⽔平布局,控件宽度超过屏幕显⽰的话,后⾯的控件都将被隐藏,不会⾃动换⾏。
常⽤的属性有:1. android:orientation:可以设置布局的⽅向2. android:id - 为控件指定相应的ID3. android:text - 指定控件当中显⽰的⽂字,需要注意的是,这⾥尽量使⽤string.xml4. android:gravity - 指定控件的基本位置,⽐如说居中,居右等位置5. android:textSize - 指定控件当中字体的⼤⼩6. android:background - 指定控件所⽤的背景⾊,RGB命名法7. android:layout_width - 指定控件的宽度8. android:layout_height - 指定控件的⾼度9. android:layout_weight - 指定控件的占⽤⽐例10. android:padding - 指定控件的内边距,也就是说控件当中的内容11. android:sigleLine - 如果设置为真的话,则将控件的内容显⽰在⼀⾏当中layout_weight属性以控制各个控件在布局中的相对⼤⼩。
android布局layout中的一些属性(DOC)

android布局layout中的一些属性1、可以使某些资源文件或UI组件可重用<include layout="@layout/other"/>2、定义一个文本编辑框,使用绝对定位android:layout_x="20dip"android:layout_y="80dip"3、控件位置android:layout_centerHorizontal 控制该组件是否位于布局容器的水平居中位置android:layout_centerVertical 控制该组件是否位于布局容器的垂直居中位置android:layout_centerInParent 控制该组件是否位于布局容器的中央位置android:layout_alignParentBottom 控制该组件是否与布局容器底端对齐android:layout_alignParentLeft 控制该组件是否与布局容器左边对齐android:layout_alignParentRight 控制该组件是否与布局容器右边对齐android:layout_alignParentTop 控制该组件是否与布局容器顶端对齐android:layout_toRightOf 控制该组件位于给出的ID组件的右侧android:layout_toLeftOf 控制该组件位于给出的ID组件的左侧android:layout_above 控制该组件位于给出的ID组件的上方android:layout_below 控制该组件位于给出的ID组件的下方android:layout_alignTop 控制该组件与给出的ID组件的上边界对齐android:layout_alignBottom 控制该组件与给出的ID组件的下边界对齐android:layout_alignLeft 控制该组件与给出的ID组件的左边界对齐android:layout_alignRight 控制该组件与给出的ID组件的右边界对齐4、设置单元格内的控件的形状(可压缩,可伸长,可隐藏等)android:shrinkColumns 设置该列的所有单元格的宽度可以被收缩,以保证该表格能够适应父容器宽度android:stretchColumns 设置该列的所有单元格的宽度可以被拉伸,以保证组件能完全填满表格空余空间android:collapseColumns 设置该列的所有单元格会被隐藏5、TextView属性设置设置字体为30pt android:textSize="30pt"设置中间省略android:singleLine="true"android:ellipsize="middle"对邮件增加链接android:autoLink="email"android:autoLink="email"测试密码框android:password="true"绘制一张图片android:drawableLeft="@drawable/icon"6、EditText属性设置当前组件在得到焦点的时候,自动选取该组件内的所有的文本内容android:selectAllOnFocus="true"当前组件只能输入数字android:phoneNumber="true"当前组件显示的提示信息,被选中时,内容自动被清空android:hint="@string/edtPhone7、按钮以及属性(B utton……)普通文字按钮android:background=""普通图片按钮<ImageButton android:src=""/>按下时显示不同图片的按钮(利用配置文件解决即,button_selector.xml,android:src="@drawable/button_selector")B utton_selector.xml:指定按钮按钮下时的图片<item android:state_pressed="true"android:drawable="@drawable/red"/>指定按钮松开时的图片:<item android:state_pressed="false"android:drawable="@drawable/purple"/>带文字的图片按钮android:background="@drawable/button_selector" android:text="@string/btnImage"8、单选按钮和多选按钮(RadioGroup、CheckBox)定义一组单选框<RadioGroup android:orientation="vertical" android:layout_gravity="center_horizontal">定义一个单选框<RadioButton android:text="@string/male"/>定义一个垂直的线性布局<LinearLayout android:layout_gravity="center_horizontal"定义三个复选框<CheckBox android:text="@string/red"android:checked="true"/>……9、带类似开关式的按钮(ToggleButton)定义一个ToggleButton按钮:<ToggleButtonandroid:textOff="@string/layoutH"android:textOn="@string/layoutV"/>定义一个可以动态改变方向的线性布局:TestActivity:ToggleButton tb = (ToggleButton) findViewById(R.id.toggle);layout = (LinearLayout) findViewById(R.id.test);匿名内部类:tb.setOnCheckedChangeListener(newOnCheckedChangeListener() {public void onCheckedChanged(CompoundButton arg0, boolean arg1) { if (arg1) {layout.setOrientation(LinearLayout.HORIZONTAL);} else {layout.setOrientation(LinearLayout.VERTICAL);}}});9、计时器组件(Chronometer)获取计时器组件:final Chronometer chro = (Chronometer) findViewById(R.id.test);改变显示的信息内容,使用"%s"表示计时信息chro.setFormat("计时信息:%s");获取“开始”按钮Button btnStart = (Button) findViewById(R.id.start);获取事件监听:btnStart.setOnClickListener(new OnClickListener() {public void onClick(View arg0) {设置开始计时时间:SystemClock系统时钟类,elapsedRealtime方法是得到当前系统的真实时间hro.setBase(SystemClock.elapsedRealtime());启动计时器:chro.start();}});时钟改变一次监听一次:chro.setOnChronometerTickListener(newOnChronometerTickListener() {public void onChronometerTick(Chronometer ch) {如果从开始计时到现在超过了20s。
Android开发之EditText属性详解

Android开发之EditText属性详解1、EditText输⼊的⽂字为密码形式的设置(1)通过.xml⾥设置:把该EditText设为:android:password="true" // 以”.”形式显⽰⽂本(2)在代码⾥设置:通过设置EditText的setTransformationMethod()⽅法来实现隐藏密码或这显⽰密码。
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());//设置密码为不可见。
2、(1)EditText输⼊的⽂字为电话号码Android:phoneNumber=”true” //输⼊电话号码3、EditText字数限制的设置(1)在.xml中设置:android:maxLength=“50”(2)代码中设置:editText.setFilters(new InputFilter[]{newInputFilter.LengthFilter(100)});4、EditText设置字体android:typeface="monospace" //设置字型。
字形有:normal, sans, serif,monospace5、EditText是否可编辑Android:editable // 是否可编辑6、在EditText中软键盘的调起、关闭(1)EditText有焦点(focusable为true)阻⽌输⼊法弹出editText=(EditText)findViewById(R.id.txtBody);editText.setOnTouchListener(new OnTouchListener(){public boolean onTouch(View v, MotionEvent event){editText.setInputType(InputType.TYPE_NULL); //关闭软键盘return false;}});(2)当EidtText⽆焦点(focusable=false)时阻⽌输⼊法弹出InputMethodManager imm =(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);imm.hideSoftInputFromWindow(editText.getWindowToken(),0);(3)调⽤数字键盘并设置输⼊类型和键盘为英⽂etNumber.setInputType(InputType.TYPE_CLASS_NUMBER); //调⽤数字键盘rlEditText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);//设置输⼊类型和键盘为英⽂或者:android:inputType="textUri|textMultiLine"(4)android:focusable="false"//键盘永远不会弹出<activity android:name=".AddLinkman"android:windowSoftInputMode="adjustUnspecified|stateHidden"/>//不⾃动弹出键盘//关闭键盘(⽐如输⼊结束后执⾏) InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(etEditText.getWindowToken(), 0);//⾃动弹出键盘((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS); etEditText.requestFocus();//让EditText获得焦点,但是获得焦点并不会⾃动弹出键盘7、android:layout_gravity和android:gravity的区别(1)android:layout_gravity是本元素对⽗元素的重⼒⽅向。
android线性布局参数详解

android线性布局参数详解/trampou/article/details/5752533线性布局中,有4个及其重要的参数,直接决定元素的布局和位置,这四个参数是android:layout_gravity (是本元素相对于父元素的重力方向)android:gravity (是本元素所有子元素的重力方向)android:orientation (线性布局以列或行来显示内部子元素)android:layout_weight (线性布局内子元素对未占用空间【水平或垂直】分配权重值,其值越小,权重越大。
前提是子元素设置了android:layout_width = "fill_parent" 属性(水平方向)或android:layout_height = "fill_parent"属性(垂直方向)如果某个子元素的android:layout_width = "wrap_content"或android:layout_height ="wrap_content”,则android:layout_weight 的设置值对该方向上空间的分配刚好相反。
下面以一个简单例子来说明这4个参数<?xml version="1.0"encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"android:layout_height="200dp"android:layout_width="200dp"android:background="#AABBCC"android:orientation="horizontal"android:layout_gravity= "center"><TextView android:text="ONE"android:background="#aa0000"android:layout_height="wrap_content"android:layout_width="wrap_content"android:layout_margin="1dp"/><TextView android:text="TWO"android:background="#aa0000"android:layout_height="wrap_content"android:layout_width="wrap_content"android:layout_margin="1dp"/></LinearLayout >说明:在上面的例子中,根布局是LinearLayout,其包含有2个TextView视图,为了对参数android:layout_gravity 有直观的了解,对根布局LinearLayout 特意加了3 个参数android:layout_height = "200dp"android:layout_width="200dp"android:background="#AABBCC"为布局指定了固定的宽度和高度,以及背景颜色,上面的例子运行后效果如下图:说明:对LinearLayout中的参数android:layout_gravity 来说,其意义是指定本布局相对于父布局的重力方向,由于该布局的已经是根布局,其父布局是整个屏幕,那么该参数设置的是相对于屏幕的位置,可以换不同的参数top|bottom|left|right等等参数来试验。
安卓面试问答题

安卓面试问答题(总15页)--本页仅作为文档封面,使用时请直接删除即可----内页可以根据需求调整合适字体及大小--二、问答题1.说明使用操作栏为程序开发所带来的便利。
答案:操作栏代替了传统的标题栏功能,右侧用来显示“选项菜单”的菜单项,但所显示的内容,会根据操作栏所具有的空间不同而具有不同的显示方式。
在屏幕尺寸较小的设备上,操作栏会自动隐藏菜单项的文字,而仅现实菜单项的图标;而在屏幕尺寸较大的设备上,操作栏会同时现实菜单项的文字和图标。
操作栏提供多个实用的功能,包括(1)将“选项菜单”的菜单项现实在操作栏的右侧;(2)基于Fragment实现类似于Tab页的导航切换功能;(3)为导航提供可“拖拽—放置”的下拉列表;(4)可在操作栏上实现类似于“搜索框”的功能。
2.写出android中主要的三种数据存储方式。
答案一:数据存储方式有三种:一个是文件,一个是数据库,另一个则是网络。
答案二:常用的数据存储方式:SharePreference存储、File存储(分为手机内存存储和SD卡存储)、SQLite数据库存储和网络存储。
答案三: 2.文件存储数据库方式4.内容提供器(Content provider)5. 网络存储方式3.简述android中的适配器作用,android有哪些适配器区别是什么答案:作用:把一些数据给弄得适当,适合以便于在View上显示。
我们常用的适配器一共有三个,ArrayAdapter,SimpleAdapter,SimpleCursorAdapter ,他们都是继承BaseAdapter其中以ArrayAdapter最为简单,只能展示一行字。
SimpleAdapter有最好的扩充性,可以自定义出各种效果。
SimpleCursorAdapter可以认为是SimpleAdapter对数据库的简单结合,可以方面的把数据库的内容以列表的形式展示出来。
4.说明线程的两种实现方式是什么?答案:第一种方式:使用Runnable接口创建线程。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1.gravity 这个英文单词是重心的意思,在这里就表示停靠位
置的意思。
android:layout_gravity 和android:gravity 的区别
从名字上可以看到,android:gravity是对元素本身说的,元素本身的文本显示在什么地方靠着换个属性设置,不过不设置默认是在左侧的。
android:layout_gravity是相对与它的父元素说的,说明元素显示在父元素的什么位置。
比如说button:android:layout_gravity 表示按钮在界面上的位置。
android:gravity表示button上的字在button上的位置。
可选值
这两个属性可选的值有:top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical。
而且这些属性是可以多选的,用“|”分开。
默认这个的值是:Gravity.LEFT
对这些属性的描述:
出自:
/guide/topics/resources/drawable-res ource.html
/reference/android/graphics/drawable /ClipDrawable.html
Value Description
top Put the object at the top of its container, not changing its size.
将对象放在其容器的顶部,不改变其大小.
bottom Put the object at the bottom of its container, not changing its size.
将对象放在其容器的底部,不改变其大小.
left Put the object at the left edge of its container, not changing its size.
将对象放在其容器的左侧,不改变其大小.
right Put the object at the right edge of its container, not changing its size.
将对象放在其容器的右侧,不改变其大小.
center_vertical Place object in the vertical center of its container, not changing its size.
将对象纵向居中,不改变其大小.
垂直对齐方式:垂直方向上居中对齐。
fill_vertical Grow the vertical size of the object if needed so it completely fills its container.
必要的时候增加对象的纵向大小,以完全充满其容器.
垂直方向填充
center_horizontal Place object in the horizontal center of its container, not changing its size.
将对象横向居中,不改变其大小.
水平对齐方式:水平方向上居中对齐
fill_horizontal Grow the horizontal size of the object if needed so it completely fills its container.
必要的时候增加对象的横向大小,以完全充满其容器.
水平方向填充
center Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
将对象横纵居中,不改变其大小.
fill Grow the horizontal and vertical size of the object if needed so it completely fills its container. This is the default.
必要的时候增加对象的横纵向大小,以完全充满其容器. clip_vertical Additional option that can be set to have the top and/or bottom edges of the child clipped to its container's bounds. The clip is based on the vertical gravity: a top gravity clips the bottom edge, a bottom gravity clips the top edge, and neither clips both edges.
附加选项,用于按照容器的边来剪切对象的顶部和/或底部的内容. 剪切基于其纵向对齐设置:顶部对齐时,剪切底部;底部对齐时剪切顶部;除此之外剪切顶部和底部.
垂直方向裁剪
clip_horizontal Additional option that can be set to have the left and/or right edges of the child clipped to its container's bounds. The clip is based on the horizontal gravity: a left gravity clips the right edge, a right gravity clips the left edge, and neither clips
both edges.
附加选项,用于按照容器的边来剪切对象的左侧和/或右侧的内容. 剪切基于其横向对齐设置:左侧对齐时,剪切右侧;右侧对齐时剪切左侧;除此之外剪切左侧和右侧.
水平方向裁剪
简单记忆:horizontal 都是操作的水平方向,即横向,vertical 都是炒作的垂直方向,即纵向。
对于LinearLayout何时生效的问题
参看:也谈layout_gravity和gravity
/viewthread.php?tid=325
对于LinearLayout
当android:orientation="vertical" 时,只有水平方向的设置才起作用,垂直方向的设置不起作用。
即:left,right,
center_horizontal 是生效的。
当android:orientation="horizontal" 时,只有垂直方向的设置才起作用,水平方向的设置不起作用。
即:top,bottom,center_vertical 是生效的。