【发布时间】:2017-01-23 19:20:42
【问题描述】:
我有一个水平方向的线性布局,权重总和为 3,左右两端有 2 个文本视图,中间有一个开关。我无法将文本视图对齐到右端并将开关对齐到中心。我使用了重心和重心端,但它们不起作用
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:padding="@dimen/rm_dashboard_ll_padding"
android:weightSum="3"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/available"
android:textColor="#82BCB4"
android:textSize="@dimen/available_textsize"
android:layout_weight="1"/>
<Switch
android:id="@+id/theSwitchId"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:switchMinWidth="@dimen/rm_switch_minwidth"
android:track="@drawable/switch_bg"
android:layout_marginStart="@dimen/margin_start_switch"
android:thumbTint="#224e6d"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/margin_left_switch"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/unavailable"
android:textColor="#224e6d"
android:textSize="@dimen/unavailable_textsize"
android:layout_gravity="end"
android:layout_weight="1"/>
</LinearLayout>
【问题讨论】:
-
你想达到什么目的?有截图吗?
-
在您的代码中,我只需添加
android:gravity="right"这个就可以了
标签: android android-layout android-linearlayout android-layout-weight