Dendrowen Dendrowen - 1 month ago 6
Android Question

Views in Linear layout don't align properly

Following code produces the result in the blueprint:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/marker_shape">

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/marker_header">

<TextView
android:id="@+id/widget_1_header_from"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"/>

<Button
android:id="@+id/widget_1_refresh"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/quantum_ic_refresh_white_24"/>

</LinearLayout>

<ListView
android:id="@+id/widget_1_list"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:layout_width="match_parent"
android:dividerHeight="0dp"
android:layout_height="wrap_content">

</ListView>

</LinearLayout>


As you can see: the TextView gets displayed beneath the Button. They need to go next to each other. How do I fix this?

blueprint

T.S T.S
Answer

You have 2 options:

  1. Change your button's height to wrap_content.

or:

  1. change your textview height to match_parent.