在android中的控件LinearLayout 中的android:gravity="center" 属性,要么是居左、居右、居中对齐,不能达到双控件 两端对齐,要实现两端对齐方式,要采用 中间增加一个控件的方式实现 ,并设置属性weight=1。
-
<LinearLayout
-
android:layout_width= "match_parent"
-
android:layout_height= "wrap_content"
-
android:orientation= "horizontal"
-
android:padding= "10dp">
-
<TextView
-
android:id= "@+id/tv_name"
-
style= "@style/commanditem_name_tv"/>
-
<TextView
-
android:layout_width= "wrap_content"
-
android:layout_height= "wrap_content"
-
android:layout_weight= "1" />
-
<com.dashuai.view.SwitchButton
-
android:id= "@+id/switch_com"
-
style= "@style/SwitchButtonStyle"
-
android:layout_marginRight= "10px"/>
-
</LinearLayout>