0

I'm using Listview in my application and when the listview is loaded with data, it covers up everything that is on the screen. I've tried everything but may be I'm just missing something. Here is my code

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/friendtilefragment">
<Button
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="Hello"
   android:layout_alignTop="@+id/list"/>
<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@color/list_divider"
android:layout_marginTop="45dp"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_row_selector" />

</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>

In this layout I'm using a Button to show a fragment. But when the data is loaded in listview, the button goes underneath listview.

deejay
  • 572
  • 4
  • 18

2 Answers2

2

Are you sure you want to use FrameLayout?, It should be used to hold a single child view. Child views inside it are drawn in a stack, with the most recently added child on top, and the relative constraint like layout_alignTop won't work in FrameLayout.

Try RelativeLayout instead, and put the SwipeRefreshLayout below the button.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/friendtilefragment">
    <Button
        android:id="@+id/myButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Hello"/>
    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_below="@+id/myButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="@color/list_divider"
            android:layout_marginTop="45dp"
            android:dividerHeight="1dp"
            android:listSelector="@drawable/list_row_selector"/>
    </android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
zdd
  • 8,258
  • 8
  • 46
  • 75
0

An answer for your question is here: Limit height of ListView on Android You better use seperate layouts for listview and content under it.

Community
  • 1
  • 1
arslanbenzer
  • 489
  • 3
  • 16