user5590713
user5590713

Reputation: 35

Android Studio: Button does not show up under the listview in a linear layout

I want to have the delete button under the listview, and I tried writing it in both linear layout and relative layout, but the delete button just doesn't show up in both layout. What could be the problem?

In RelativeLayout version

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="myproject.testing.listviewwithbutton">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <AutoCompleteTextView
            android:id="@+id/autoCompleteTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="New Ingredient"
            android:layout_alignParentTop="true" />

        <Button
            android:id="@+id/addButton"
            android:layout_width="wrap_content"
            android:layout_height="41dp"
            android:text="Add"
            android:layout_alignBaseline="@id/autoCompleteTextView"
            android:layout_alignParentRight="true"/>

    </RelativeLayout>

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="457dp"
        android:id="@+id/mainListView"
        android:layout_weight="1"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom">

        <Button
            android:id="@+id/deleteButton"
            android:layout_width="wrap_content"
            android:layout_height="41dp"
            android:text="Delete"

            android:layout_gravity="center_horizontal"
            android:layout_weight="0"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" />

</RelativeLayout>

</LinearLayout>

In LinearLayout version

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <AutoCompleteTextView
            android:id="@+id/autoCompleteTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="New Ingredient"
            android:layout_alignParentTop="true" />

        <Button
            android:id="@+id/addButton"
            android:layout_width="wrap_content"
            android:layout_height="41dp"
            android:text="Add"
            android:layout_alignBaseline="@id/autoCompleteTextView"
            android:layout_alignParentRight="true"/>

    </RelativeLayout>



    <ListView
        android:layout_width="wrap_content"
        android:layout_height="457dp"
        android:id="@+id/mainListView"
        android:layout_weight="1"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="41dp"
        android:id="@+id/deleteButton"
        android:text="Delete"
        android:layout_weight="0"
        android:layout_gravity="center_horizontal"/> 

</LinearLayout>

Upvotes: 0

Views: 76

Answers (1)

chiru
chiru

Reputation: 645

Instead of making different layout for each views, using single relative layout with below attributes:

  1. AutoCompleteTextView & Add button - no changes
  2. Delete button - align parent bottom as true
  3. List view - align below AutoCompleteTextView and align above delete button

Upvotes: 1

Related Questions