代理ip提取网站源码,网络优化seo是什么工作,软件开发交付流程,济南市商务局官方网站本篇博文只针对LinearLayout与RelativeLayout 我们在新建一个布局文件时#xff0c;一般遵循这样的思路#xff1a;先确定该文件对应的界面中各个布局和控件的位置和大小#xff0c;然后再来设置各个布局和控件的其他属性#xff0c;如背景、文字等。 上篇 确定控件的位… 本篇博文只针对LinearLayout与RelativeLayout 我们在新建一个布局文件时一般遵循这样的思路先确定该文件对应的界面中各个布局和控件的位置和大小然后再来设置各个布局和控件的其他属性如背景、文字等。 上篇 确定控件的位置和尺寸 在确定各个布局和控件的位置和大小时首先需要考虑的是最外层的Layout的位置有如下两种方法可以采用 1、直接设置最外层的Layout填充父窗体即 android:layout_widthmatch_parent android:layout_heightmatch_parent 这将不涉及Layout与父窗体边缘的距离设置。 2、设置最外层Layout的长宽中的一个或两个的值刚好适应子布局和控件的尺寸即 设置android:layout_width 、android:layout_height 中的一个或两个属性的值为wrap_content 这种情况下Layout默认是左边缘和上边缘与父窗体对齐如果想改变它的显示位置可使用如下几种方式 A、直接用一个具体的值来指定Layout与父窗体边缘的距离需要使用这几个属性 android:layout_marginLeft设置该Layout距离父窗体左边缘的距离android:layout_marginTop设置该Layout距离父窗体上边缘的距离 B、用非具体数值的方式来确定Layout在父窗体中的位置需要使用这几个属性 android:layout_gravity 可以选择的常用值有center_vertical、center_horizontal竖直居中、水平居中等 但需要注意的是使用A、B两种方式是会有冲突的这会增加维护的难度最好不要同时使用。 上述解决了Layout在父窗体中的位置和大小设置的问题LinearLayout与RelativeLayout皆适用。 那么一个 LinearLayout或RelativeLayout中的控件布局的位置 又是怎么来确定呢 在界面比较复杂的情况下我们可以先将这个Layout中的所有子Layout和控件都视为子控件待处理完这个Layout中的子控件的位置后再来处理子Layout中的控件的位置和大小有点类似递归的思想。 同样在设置Layout中的控件的位置时LinearLayout与RelativeLayout也有很多可以共用的属性 比如使用如下几种方式来设置 A、直接用一个具体的值来指定Layout中的内容与Layout边缘的距离需要使用这几个属性 android:paddingLeft设置该Layout中的内容距离该Layout左边缘的距离android:paddingTop设置该Layout中的内容距离该Layout上边缘的距离android:paddingRight设置该Layout中的内容距离该Layout右边缘的距离android:paddingBottom设置该Layout中的内容距离该Layout下边缘的距离 B、用非具体数值的方式来确定该Layout中的内容的位置需要使用以下属性 android:gravity 可以选择的常用值有center_vertical、center_horizontal、right竖直居中、水平居中、靠右等 但需要注意的是使用A、B两种方式是会有冲突的这会增加维护的难度最好不要同时使用。 除此之外在设置Layout中的控件的位置时LinearLayout与RelativeLayout也有很多不同的属性。 接下来分析LinearLayout与RelativeLayout的属性有何不同在使用时怎么选择 一、LinearLayout LinearLayout的注释 /*** A Layout that arranges its children in a single column or a single row. The direction of * the row can be set by calling {link #setOrientation(int) setOrientation()}. * You can also specify gravity, which specifies the alignment of all the child elements by* calling {link #setGravity(int) setGravity()} or specify that specific children * grow to fill up any remaining space in the layout by setting the emweight/em member of* {link android.widget.LinearLayout.LayoutParams LinearLayout.LayoutParams}.* The default orientation is horizontal.*/
//LinearLayout 将它的子布局(控件)排成一行或一列可以调用setOrientation()方法来设置排列
//的方向或者调用setGravity()方法 //来指定子布局(控件)的对齐方式还可以设置weight的值
//来改变子布局(控件)的填充范围默认排列方向是horizontal
public class LinearLayout extends ViewGroup {} 在设置Layout里边的控件的位置时LinearLayout中的控件可以使用的属性有 A、设置该控件距左、上、右、下边无论是父控件还是兄弟控件的长度在RelativeLayout中也适用 android:layout_marginLeft设置该控件距左边无论是父控件还是兄弟控件的长度android:layout_marginTop设置该控件距上边无论是父控件还是兄弟控件的长度android:layout_marginRight设置该控件距右边无论是父控件还是兄弟控件的长度android:layout_marginBottom设置该控件距下边无论是父控件还是兄弟控件的长度 B、用非具体数值的方式来确定该控件在父窗体中的位置需要使用这几个属性 android:layout_gravity 可以选择的常用值有center_vertical、center_horizontal竖直居中、水平居中等 C、在控件内用android:layout_weight 属性修改控件在父控件中的填充比例 关于这个属性的使用这里不再讲述网上已有分析链接如下 layout_weight的深刻理解 二、RelativeLayout RelativeLayout的注释 /*** A Layout where the positions of the children can be described in relation to each other or to the* parent.*/
//在RelativeLayout中可以依据一个子布局(控件)与其他子布局(控件)
//或者父窗体的相对位置关系来描述它的位置
public class RelativeLayout extends ViewGroup {} 在设置Layout里边的控件的位置时RelativeLayout中的控件可以使用的属性有 A、设置该控件和父控件的相对位置属性值为true或false android:layout_centerHrizontal水平居中android:layout_centerVertical垂直居中android:layout_centerInparent相对于父元素完全居中android:layout_alignParentBottom贴紧父元素的下边缘android:layout_alignParentLeft贴紧父元素的左边缘android:layout_alignParentRight贴紧父元素的右边缘android:layout_alignParentTop贴紧父元素的上边缘 B、设置该控件和某个兄弟控件的相对位置属性值为控件的id android:layout_below在某元素的下方android:layout_above在某元素的的上方android:layout_toLeftOf在某元素的左边android:layout_toRightOf在某元素的右边android:layout_alignBaseline本元素的baseline和给定元素的baseline对齐android:layout_alignTop本元素的上边缘和某元素的的上边缘对齐android:layout_alignLeft本元素的左边缘和某元素的的左边缘对齐android:layout_alignBottom本元素的下边缘和某元素的的下边缘对齐android:layout_alignRight本元素的右边缘和某元素的的右边缘对齐 C、设置该控件距左、上、右、下边无论是父控件还是兄弟控件的长度属性值为具体值如30dip在LinearLayout中也适用 android:layout_marginLeft设置该控件距左边无论是父控件还是兄弟控件的长度android:layout_marginTop设置该控件距上边无论是父控件还是兄弟控件的长度android:layout_marginRight设置该控件距右边无论是父控件还是兄弟控件的长度android:layout_marginBottom设置该控件距下边无论是父控件还是兄弟控件的长度 下篇 确定控件的其他属性 以下为各个控件的常用属性总结 待补充 转载于:https://www.cnblogs.com/hwgt/p/5414401.html