Android ApiDemos示例解析(140):Views->Layouts->Baseline->Nested Example 3

本文介绍如何通过设置两层LinearLayout的属性实现基线对齐。第一层LinearLayout的android:baselineAlignedChildIndex属性指向第二层LinearLayout,而第二层LinearLayout内的TextView则作为基线对齐的目标。文中特别指出在进行基线对齐时需要去除特定的布局重力属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本例使用了两层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”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值