Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 關於android開發 >> 和我一起看API(一)你所不知道的LinearLayout補充,apilinearlayout

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

編輯:關於android開發

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


樓主英語水平差,翻譯的不好的話請多多指正,嘿嘿。。。


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"

從今晚開始每晚翻譯一點,貴在堅持。。。堅持大叔

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved