Контекст: У меня есть виджет, который в основном состоит из RelativeLayout, обертывающего кучу TextViews.Вот как я хочу, чтобы виджет выглядел визуально, а затем код XML-макета:
![Expected layout](https://i.stack.imgur.com/X9JVx.png)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/alarm_widget_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/alarm_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="8:30"
android:textSize="40sp"
/>
<TextView
android:id="@+id/alarm_am_pm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/alarm_time"
android:layout_marginLeft="2dp"
android:layout_alignTop="@id/alarm_time"
android:textSize="18sp"
android:text="AM"
/>
<TextView
android:id="@+id/alarm_days"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/alarm_time"
android:textSize="16sp"
android:text="M T W T F S S"
/>
<TextView
android:id="@+id/toggle_indicator"
android:layout_height="8sp"
android:layout_width="80sp"
android:layout_below="@id/alarm_days"
android:layout_centerHorizontal="true"
android:background="@drawable/toggle_button_oval"
/>
</RelativeLayout>
Вопрос: Я в тупикепротиворечивое поведение layout_marginLeft в следующих сценариях:
- Когда эти виджеты располагаются вертикально внутри LinearLayout, для текста AM / PM в верхнем правом углу требуется android: layout_marginLeft = "15dp", чтобы выглядеть такэто показано на рисунке выше.
- Однако, когда виджеты сложены в TableLayout 2x2, текст AM / PM требует, чтобы android: layout_marginLeft = "2dp" выглядел правильно.
Почему я вижу это противоречивое поведение?Что использует layout_marginLeft в качестве «источника»?