2

I have spent enough time to make it work for my listview to setProperty "above" of layout which align_parentBottom=true.

Seems like very easy right? No its not.

Please see this image so you can visualize the problem and have some idea about it.

enter image description here

When User scrolls listview, home button @bottom hides.

And by default, home button stays as it is if list scrolling is in idle state. This needs to be done.

So my problem is that After home button Visibility goes GONE then listview fills whole space towards bottom means MATCH_PARENT, thats fine.

But when scroll reaches to idle state & Visibility set to Visible then last Item of listview goes/hides behind home button.

It means listview is not getting to its original place as Image shows.

Tried By making it programmatically to set "above" property of list as Home Button is align_parentBottom=true.

also tried by changing whole layout to Linear layout and giving weight=1.

But didn't succeed. Any help will be appreciated.

Thanks.

Layout File Fragement:

<LinearLayout
    android:id="@+id/llmain"
    android:visibility="visible"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical">

    <TextView
        android:id="@+id/txtTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/d_10"
        android:layout_marginTop="@dimen/d_5"
        style="@style/text_size_title"
        android:textColor="@color/black"
        android:textStyle="bold" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/d_10"
        android:layout_marginRight="@dimen/d_10"
        android:layout_marginTop="@dimen/d_5">

        <TextView
            android:id="@+id/txtDateTime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/comment_n_time_color_text"
            android:textSize="14sp" />

        <LinearLayout
            android:layout_width="@dimen/d_1"
            android:layout_height="match_parent"
            android:layout_marginLeft="@dimen/d_3"
            android:layout_marginRight="@dimen/d_3"
            android:background="@color/comment_n_time_color" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:src="@drawable/ic_like" />

        <TextView
            android:id="@+id/txtLike"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/d_3"
            android:layout_marginRight="@dimen/d_3"
            android:textColor="@color/comment_n_time_color_text"
            android:textSize="14sp" />

        <LinearLayout
            android:layout_width="@dimen/d_1"
            android:layout_height="match_parent"
            android:layout_marginLeft="@dimen/d_3"
            android:layout_marginRight="@dimen/d_3"
            android:background="@color/comment_n_time_color" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:src="@drawable/comment" />

        <TextView
            android:id="@+id/txtComment"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/d_3"
            android:layout_marginRight="@dimen/d_3"
            android:textColor="@color/comment_n_time_color_text"
            android:textSize="14sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/article_detail_separator"
        android:layout_marginTop="@dimen/d_5"
        android:background="@color/comment_n_time_color"></LinearLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/d_10"
        android:layout_marginTop="@dimen/d_5"
        android:text="@string/article_comment"
        android:textAppearance="?android:textAppearanceMedium"
        android:textColor="@color/black"
        android:textStyle="bold" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/d_10"
        android:layout_marginRight="@dimen/d_10"
        android:layout_marginTop="@dimen/d_5"
        android:orientation="horizontal">

        <EditText
            android:id="@+id/txt_message"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="@dimen/d_10"
            android:layout_weight="1"
            android:hint="@string/article_comment_hint"
            android:textColor="@color/black" />

        <ImageView
            android:id="@+id/img_send"
            android:padding="@dimen/d_10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:src="@drawable/send_button" />

    </LinearLayout>

    <ListView
        android:id="@+id/listview_comments"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:cacheColorHint="@null"
        android:listSelector="@null">
    </ListView>
</LinearLayout>

And My Activity Layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/parent"
    android:background="@android:color/white">

    <include
        android:id="@+id/toolbaar"
        layout="@layout/partial_toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_alignParentTop="true" />

    <View
        android:layout_below="@+id/toolbaar"
        android:id="@+id/viewline"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="@color/separator_color" />

    <FrameLayout
        android:layout_above="@+id/llbottom"
        android:layout_below="@+id/viewline"
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></FrameLayout>

    <LinearLayout
        android:id="@+id/llbottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">

        <include
            android:id="@+id/img_home_"
            layout="@layout/home_icon_footer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
</RelativeLayout>
Sagar Shah
  • 4,272
  • 2
  • 25
  • 36

3 Answers3

0

I think you might be able to solve your problem by having one parent view, lets just say a relative view, and then have three different views inside that relative view. So it would look like relative view then inside that you can have a view for your elements above the list View, then a ScrollView with your listview inside that and finally another view, probably a relative view, after that for the home button and make sure to align_parentBottom=true.

user2946061
  • 33
  • 1
  • 6
  • And why is that will I use ListView inside scrollView? – Sagar Shah Apr 29 '15 at 12:06
  • it doesn't necessarily have to be a scrollview, it can be a linerlayout view or relative view. I believe this problem that you're having is just being caused by the formatting of you layouts in your xml. – user2946061 Apr 29 '15 at 12:15
  • Actually whats happening here might shock you. Whenever listview show items say 5 items when home@botom is not visible.And then try to visible the home btn-listview will not change its height for sure.Try it for fun.You will know why. – Sagar Shah Apr 29 '15 at 12:18
0

You have to put one layout(Linearlayout) at bottom with "Wrap_content" and along_parentbottom=true and inside that layout put your home bottom. Now when you set home button visibility to GONE layout your layout still there with 0 height and when you make it visible its inside layuout so list does not cover whole part.

Amit
  • 409
  • 1
  • 5
  • 12
0

I have fix this issue by

listview.scrollTo(0 , homeBtn.getHeight());

Which actually moves my list items to scroll on up Y direction when I get last item or say When there is not the first item of the list.

Sagar Shah
  • 4,272
  • 2
  • 25
  • 36