1

I am new to android layout and having the following problem in my app:

here's the layout for fragment

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
android:layout_margin="0dp">
<ListView
    android:id="@+id/listview_books_to_issue"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.87"

    />

<ImageView
    android:id="@+id/imageView_empylist"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.87"
    android:src="@drawable/ic_empty_flask"
    android:visibility="gone"/>
<View
    style="@style/Divider"/>

<Button
    android:id="@+id/add_newbook_upcoming_issues"
    android:layout_width="match_parent"
    android:text="New"
    android:paddingTop="5dp"
    android:layout_height="0dp"
    android:layout_weight="0.13"
    android:drawableTop="@drawable/ic_add"
    android:background="?android:attr/selectableItemBackground"/>

I turn the ImageView's(imageView_empylist) visibility on when the ListView(listview_books_to_issue) is empty, so far the button add_newbook_upcoming_issues looks good, but when the listview is populated even with a single item the button gets hidden partially in the bottom.

Here's the layout code for the item used to populate list.

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

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

    <TextView
        android:id="@+id/textview_upcoming_issues_book_title"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.3"
        android:textAlignment="center"
        android:gravity="center_vertical"
        android:text="Title"/>

    <TextView
        android:id="@+id/textview_upcoming_issues_book_author"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.3"
        android:textAlignment="center"
        android:gravity="center_vertical"
        android:text="By:-Author"/>

    <TextView
        android:id="@+id/textview_to_issue_date"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.3"
        android:textAlignment="center"
        android:gravity="center_vertical"
        android:text="to be issued on"/>
    <TextView
        android:id="@+id/textview_upcoming_issues_book_no"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.1"
        android:visibility="gone"/>

</LinearLayout>

Don't know what's causing it, any help? Thanks in advance :)

PS: I am using weights instead of height so that I can have a fixed ratio of screen for items. If in case this is causing the problem please mention the correct way of doing this.

EDIT found the solution here Limit height of ListView on Android

Community
  • 1
  • 1
Salim
  • 143
  • 11

1 Answers1

0

In your main layout fragment, please use RealativeLayout replace for LinearLayout. Your ListView will be layout_above for these views

Liem Vo
  • 5,149
  • 2
  • 18
  • 16