lundi 25 mai 2015

Cannot independently set padding on TextViews

While testing some designs for a LinearLayout for the elements in a ListView, I stumbled upon some weird behaviour. As you can see in the added code, I have three TextViews in a horizontal LinearLayout. I wanted to set the padding for one of these TextViews, but it seems that this value is also applied to the other TextViews as a margin of some sort (see pictures).

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="48dp">

    <TextView
        android:id="@+id/search_list_row_symbol"
        android:layout_width="wrap_content"
        android:layout_height="16dp"
        android:paddingTop="0dp"
        android:layout_marginTop="0dp"
        android:textSize="16sp"
        android:background="@android:color/holo_blue_light"
        android:text="O"/>

    <TextView
        android:id="@+id/search_list_row_name"
        android:layout_width="0dp"
        android:layout_height="48dp"
        android:layout_weight="1"
        android:paddingTop="0dp"
        android:layout_marginTop="0dp"
        android:textSize="16sp"
        android:background="@android:color/holo_red_light"
        android:text="oxygen"/>

    <TextView
        android:id="@+id/search_list_row_number"
        android:layout_width="wrap_content"
        android:layout_height="20dp"
        android:paddingTop="0dp"
        android:layout_marginTop="0dp"
        android:textSize="16sp"
        android:background="@android:color/holo_green_light"
        android:text="8"/>

</LinearLayout>

Set android:paddingTop="0dp" on all TextViews padding_top_set_to_0

Set android:paddingTop="16dp" only on first TextView padding_top_set_to_16

Do any of you know why the padding cannot be set independently on one of these TextViews?

Aucun commentaire:

Enregistrer un commentaire