LinearLayout内部控件使用gravity和layout_gravity的注意点

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ruizhenggang/article/details/85256962

在安卓中,只有垂直的linearlayout属性里面的内部组件靠左靠右才有效,同理,水平的linearlayout属性里面的内部组件靠上靠下才有效,否则无效由此考虑如何让水平linearlayout中同一行内组件靠左靠右显示呢。废话不多说,直接上代码,注意点,标红。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical|right">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1">
    <Switch
        android:id="@+id/hand_send_switch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/self_help_dp_10"
        android:layout_gravity="left|center_vertical"
        android:checked="true"
        android:text="@string/layout_activity_phone_order_online_05"
        android:textSize="@dimen/text_size_16"/>
    </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            >
    <Switch
        android:id="@+id/wechat_switch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/self_help_dp_10"
        android:checked="true"
        android:layout_gravity="right|center_vertical"
        android:text="@string/layout_activity_phone_order_online_03"
        android:textSize="@dimen/text_size_16"/>
        </LinearLayout>

</LinearLayout>

猜你喜欢

转载自blog.csdn.net/ruizhenggang/article/details/85256962
今日推荐