2016-01-16 2 views
-1

Я хочу иметь отступы между текстом описания и переключателем, но свойство paddingRight не работает. Зачем?Android: Padding не работает в RelativeLayout

enter image description here

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/layoutLayout" 
    android:layout_below="@+id/layoutHeader" 
    android:layout_marginTop="15dp" 
    android:layout_marginLeft="15dp" 
    android:layout_marginRight="15dp"> 

    <Switch 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/widgetShortSwitch" 
     android:layout_centerVertical="true" 
     android:layout_alignParentRight="true" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="This is a long description text that should not overlay." 
     android:textColor="#000000" 
     android:paddingRight="15dp" 
     android:id="@+id/widgetShortTextView" 
     android:layout_centerVertical="true" 
     android:layout_alignParentLeft="true" 
     /> 
</RelativeLayout> 

ответ

1

Попробуйте это ...

<?xml version="1.0" encoding="utf-8"?> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/layoutLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/layoutHeader" 
     android:layout_marginLeft="15dp" 
     android:layout_marginRight="15dp" 
     android:layout_marginTop="15dp" 
     android:weightSum="1"> 

     <TextView 
      android:id="@+id/widgetShortTextView" 
      android:layout_width="0" 
      android:layout_height="wrap_content" 
      android:paddingBottom="5dp" 
      android:layout_weight="0.85" 
      android:paddingRight="15dp" 
      android:text="This is a long description text that should not overlay." 
      android:textColor="#000000" /> 

     <Switch 
      android:id="@+id/widgetShortSwitch" 
      android:layout_width="0" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:layout_weight="0.15" /> 
    </LinearLayout> 
+0

Awesome. Когда вы добавляете единицы «dp» к вашим макетам, это идеально. – Kewitschka

0

Вы должны сказать, что ваш RelativeLayout TextView остается коммутаторе. Вы также должны поместить свой TextView в alignParentLeft, чтобы он начинался слева.

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/layoutLayout" 
    android:layout_below="@+id/layoutHeader" 
    android:layout_marginTop="15dp" 
    android:layout_marginLeft="15dp" 
    android:layout_marginRight="15dp"> 

    <Switch 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/widgetShortSwitch" 
     android:layout_centerVertical="true" 
     android:layout_alignParentRight="true" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="This is a long description text that should not overlay." 
     android:textColor="#000000" 
     android:paddingRight="15dp" 
     android:id="@+id/widgetShortTextView" 
     android:layout_centerVertical="true" 
     android:layout_alignParentLeft="true" 
     android:layout_toLeftOf="@id/widgetShortSwitch" 
     android:layout_alignParentLeft="true" 
     /> 
</RelativeLayout> 
Смежные вопросы