2017-08-31 97 views
0

如何在开关右侧设置文本位置without在LinearLayout中对齐Switch和TextView?我试图重写复选框按钮样式在我style.xml按钮,但我不知道怎么去切换按钮参考?如何在开关右侧设置文本位置(如复选框)

+0

尝试设置'安卓重力= “RIGHT”'属性。 –

+0

@TasosMoustakas不,它不起作用。 –

回答

0

两种方式都存在,但不推荐,因为负填充所以第二个方法。

=>使用一个单独的文本视图

 <LinearLayout 
      android:layout_width="match_parent" 
      android:orientation="horizontal" 
      android:paddingTop="10dp" 
      android:paddingBottom="10dp" 
      android:layout_height="wrap_content"> 
      <Switch 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/switch1" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:text="This is a switch" 
       android:layout_height="wrap_content" /> 
     </LinearLayout> 

编辑 - 有没有直接的方法,但使用负填充,父布局或任何自定义库。 见herehere
忘掉这个并使用this library

+0

感谢您的回答,但是这正是我不想做的事。 –

相关问题