I have a ListView
that displays two items in a row. The View
that displays one row has a LinearLayout
as it's root:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<LinearLayout
android:id="@+id/layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/grey"
android:gravity="center_vertical">
<TextView
android:id="@+id/textview1"
style="@style/refinement_button"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="@color/white"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<LinearLayout
android:id="@+id/layout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/grey"
android:gravity="center_vertical">
<TextView
android:id="@+id/textview2"
style="@style/refinement_button"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="@color/white"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
In the editor in Android Studio I see
but on a device I see
(image recreated in editor, to save time)
I tried this on a Nexus6 with Android 7.0 and on a Nexus 5 with Android 6.0.1. I assume this is a bug in Android on the phones, or in the editor in Android Studio. The purpose of the editor is to show you what your layout looks like on a device.
I am not asking for advice on how to create a proper layout. My only point is that what shows up on my device is different from what I see in the editor in Android Studio and I wonder how come.