本例使用了两层LinearLayout嵌套:
<!– We’ll point to the linear layout to baseline align by, which
in turn will point to a text view inside of it –>
<LinearLayout
android:orientation=”vertical”
android:baselineAlignedChildIndex=”1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
<ImageView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:src=”@drawable/arrow_up_float”/>
<LinearLayout
android:orientation=”vertical”
android:baselineAlignedChildIndex=”2″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
<ImageView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:src=”@drawable/arrow_up_float”/>
<ImageView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:src=”@drawable/arrow_up_float”/>
<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginRight=”5dip”
android:text=”@string/baseline_nested_1_label”/>
</LinearLayout>
</LinearLayout>
第一层android:baselineAlignedChildIndex=”1″ 指定第二层LinearLayout ,第二个android:baselineAlignedChildIndex=”2″ 为第二级LinearLayout中的TextView,注意同样要去掉XML中的android:layout_gravity=”center_vertical”
本文介绍如何通过设置两层LinearLayout的属性实现基线对齐。第一层LinearLayout的android:baselineAlignedChildIndex属性指向第二层LinearLayout,而第二层LinearLayout内的TextView则作为基线对齐的目标。文中特别指出在进行基线对齐时需要去除特定的布局重力属性。

2万+

被折叠的 条评论
为什么被折叠?



