和我一起看API(一)你所不知道的LinearLayout补充

楼主英语水平差,翻译的不好的话请多多指正,嘿嘿。。。


A Layout that arranges its children in a single column or a single row. The direction of * the row canbe 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 <em>weight</em> member of
{@link android.widget.LinearLayout.LayoutParams LinearLayout.LayoutParams}. * The default orientation is
horizontal.
这是一个将子类排列在一列或一行的布局。通过调用 setOrientation()可以设置行的方向。您还可以指定对其方向,它指定
所有子元素的对齐方式的方法叫做{ @link # setGravity(int)setGravity()}或通过设置权重/weight(< em > < / em >的
成员)指定特定的子类填满剩余的空间布局 { @link android.widget.LinearLayout。LayoutParams LinearLayout.
LayoutParams }。默认的方向是水平的。
/**
* Don't show any dividers.
*不显示任何分割线
*/
public static final int SHOW_DIVIDER_NONE = 0;
/**
* Show a divider at the beginning of the group.
* 显示分割线在这个视图组之前
*/
public static final int SHOW_DIVIDER_BEGINNING = 1;
/**
* 显示分割线在这个布局的每个子视图之间
* Show dividers between each item in the group.
*/
public static final int SHOW_DIVIDER_MIDDLE = 2;
/**
*显示分割线在这个布局的最后
* Show a divider at the end of the group.
*/
public static final int SHOW_DIVIDER_END = 4;

首先画一根线,采用shape.xml绘制:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:shape = "rectangle">

<size
android:width= "@dimen/fab_margin"
android:height= "@dimen/fab_margin" />

<solid android:color= "#ff00ff" />

</shape>

示例代码1设置分割线显示在子类最前方:
<LinearLayout
android:layout_width="fill_parent"
android:gravity="center"
android:divider="@drawable/driver"<!--设置分割线样式-->
android:showDividers="beginning"<!--设置分割线显示方式-->
android:layout_height="fill_parent"
android:orientation="horizontal">
<Button
android:id="@+id/bt1"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="1"/>
<Button
android:id="@+id/bt2"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="2"/>
<Button
android:id="@+id/bt3"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="3"/>
</LinearLayout>
示例2显示分割线在这个布局的每个子视图之间:
<LinearLayout
android:layout_width="fill_parent"
android:gravity="center"
android:divider="@drawable/driver"
android:showDividers="end"
android:layout_height="fill_parent"
android:orientation="horizontal">
<Button
android:id="@+id/bt1"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="1"/>
<Button
android:id="@+id/bt2"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="2"/>
<Button
android:id="@+id/bt3"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="3"/>
</LinearLayout>
示例3*显示分割线在这个布局的最后:
<LinearLayout
android:layout_width="fill_parent"
android:gravity="center"
android:divider="@drawable/driver"<!--设置分割线样式-->
android:showDividers="middle"<!--设置分割线显示方式-->
android:layout_height="fill_parent"
android:orientation="horizontal">
<Button
android:id="@+id/bt1"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="1"/>
<Button
android:id="@+id/bt2"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="2"/>
<Button
android:id="@+id/bt3"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="3"/>
</LinearLayout>
示例4*显示分割线在这个布局的前后中间:
<LinearLayout
android:layout_width="fill_parent"
android:gravity="center"
android:divider="@drawable/driver"<!--设置分割线样式-->
android:showDividers="middle|beginning|end"<!--设置分割线显示方式-->
android:layout_height="fill_parent"
android:orientation="horizontal">
<Button
android:id="@+id/bt1"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="1"/>
<Button
android:id="@+id/bt2"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="2"/>
<Button
android:id="@+id/bt3"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="3"/>
</LinearLayout>

/**
* Set padding displayed on both ends of dividers.
*
* @param padding Padding value in pixels that will be applied to each end
*
* @see #setShowDividers(int)
* @see #setDividerDrawable(Drawable)
* @see #getDividerPadding()
*/

/ * *
*设置内边距显示分隔器的两端。
*
* @param内边距的值将会使用像素作为单位
*
* @see # setShowDividers(int)
* @see # setDividerDrawable(可移动)
* @see # getDividerPadding()
* /
public void setDividerPadding(int padding) {
mDividerPadding = padding;
}
android:dividerPadding="12dp"
3、
/**
* Whether the children of this layout are baseline aligned. Only applicable
* if {@link #mOrientation} is horizontal.
*/
@ViewDebug.ExportedProperty(category = "layout")
private boolean mBaselineAligned = true;
这种布局的子视图是否基线对齐。只适用水平布局--注:基线是在中间
xml代码只需要在LinearLayout布局中添加属性:
android:baselineAligned="true"
*{ @link # mOrientation }

If this layout is part of another layout that is baseline aligned,
* use the child at this index as the baseline.
*
* Note: this is orthogonal to {@link #mBaselineAligned}, which is concerned
* with whether the children of this layout are baseline aligned.
@ViewDebug.ExportedProperty(category = "layout")
*/
@ViewDebug.ExportedProperty(category = "layout")
private int mBaselineAlignedChildIndex = -1;
private int mBaselineAlignedChildIndex = -1;
如果这个布局是另一个基线对齐的布局的一部分,
*使用子视图在这个指数作为基准。
*
*注:这是正交于{ @link # mBaselineAligned },这是担心
*此布局的子视图是否基线对齐。
android:baselineAlignedChildIndex="-1"

/**
* When true, all children with a weight will be considered having
* the minimum size of the largest child. If false, all children are
* measured normally.
*
* @return True to measure children with a weight using the minimum
* size of the largest child, false otherwise.
*
* @attr ref android.R.styleable#LinearLayout_measureWithLargestChild
*/
public boolean isMeasureWithLargestChildEnabled() {
return mUseLargestChild;
}

/ * *
当为真的时候 具有相同权重/比重的所有子类被认为是最大子类的最小权重
如果为假 所有子类测量和平时权重/比重一样

android:measureWithLargestChild="true"

从今晚开始每晚翻译一点,贵在坚持。。。坚持大叔

原文地址:https://www.cnblogs.com/sunzan/p/5304063.html