Android ListView FooterView width not mach parent - android

I have a listview for display message, and I wanna add footerview to show loadmore button, if the listview set android:layout_height="fill_parent" it works normally, but I need to give it an absolute value to set listview height such as android:layout_height="400dip" so as to avoid getview method repeat calling , and then the footerview width can’t match parent.

Set the list view layout_height="fill_parent" and layout_weight="1", then anything that you put under it will have space.

Related

ListView. Hot to highlight whole listview item when touching on it

There is ListView with items which contains TextView.
When you are touching listview item and hold the finger on it, listview item is highlighted a little.
But if textview contains just a few letters - not all row is highlighted.
Is any simple solution (some xml property, etc) to highlight whole row?
Hi Set This Code In Your Xml Of ListView
=================================
<ListView android:id="#+id/list1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
you try to make listview width android:layout_width="fill_parent" .And also if u are using custom adapter for (images and text) -make layout width size-fill parent or match parent
Set android:layout_width attribute of parent Layout tag to fill_Parent for in xml for Listview.

GridView in Listview can not display well after refreshed

I add a gridview as headerview of listview,when i change gridview's content, it's height does't changes,I can only see a part of gridview's new content.I have tried invalidate,but it does't work.In the gridview,i click the more button,and then change the adapter of gridview,but i can see only a part of new content of gridview,and when i call geidview.getHeight,(),it does't change
gridView.getHeight() will not return the height of the gridView. It would return 0. This is because the gridView would get layed out only after the view has been rendered. You could check the android documentation for this.
If you want to add the header, then set a minHeight on the gridView something like :
<GridView
android:minHeight="5dp" />
This will ensure that the header has a minHeight of 5dp.

How to get some space below my last list item alone- android

I have a list whose height is set to "fill parent". everything works fine but my last item in list touches the bottom of my screen. how can i get some space below my last list item.
You can add an empty view as footer: http://developer.android.com/reference/android/widget/ListView.html#addFooterView(android.view.View)
AFAIK there's no way to do that only with XML, you can declare the footer in XML and inflate, or create programmatically
Here is a 3-liner to add a spacer programmatically:
View listFooter = new View(this);
listFooter.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.FILL_PARENT, 70)));
listView.addFooterView(listFooter);
uhmm.. seeing that you don't want padding, print a blank line (or transparent text) on a textview located after your listview. Or print a "extra" item on your listview.
you could use the Space widget
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="10dp"/>
can simply set the margin in the list ............
if need only bottom margin then use : android:layout_marginBottom=

How to set a standard height of a listview row

In iOS programming I have to implement (or at least if I don't want the default one...) an method which returns the height of the row. I am probably blind because I can't find the method where I set the height of the row in a listview in Android.
I have created custom row layouts, so I start to think that I set the height in the parent layout manager in the XML. Can anyone confirm that this is the way to do it? Or is it a method?
You'll need to set the height in the layout xml for the row itself. If you absolutely want every row to be the same height, set:
android:minHeight="80dp"
android:maxHeight="80dp"
in your base layout (Should be a LinearLayout or RelativeLayout, likely) of the listview row. Note you can do:
android:minHeight="?android:attr/listPreferredItemHeight"
android:maxHeight="?android:attr/listPreferredItemHeight"
to be inline with (most) other applications.
Yes, the only way to set the height of the row is to mention it's dimensions in the xml ,for the list item or you can also set the height of the list item in the getView() method of listView if you have a custom Adapter. There is no listView method as such to define the height of the row.

Divider disappears from last item in listview if footerview added

If footer view added in ListView, then divider disappears from last item of ListView.
Even I have set android:footerDividersEnabled="true" with ListView and my footer view is just TextTiew.
Setting isSelectable to true didn't work for me, maybe because I was also calling removeFooterView when my list was done loading.
What finally fixed it for me was setting android:layout_height to "fill_parent" instead of "wrap_content" on the ListView.
The ListView implementation in Android never draws dividers between items that are disabled, which if you are just calling the addFooterView(View v) method then by default your footer will be.
Instead you need to call the addFooterView(View v, Object data, boolean isSelectable) method with isSelectable set to true. You can just pass null for the data object if you don't need it.
This almost worked for me. I was after a divider after the last list item, but not after the footer as my footer was empty space. I ended up adding two footers, one selectable of zero height and one not selectable containing the padding.
TextView view = new TextView(this);
view.setLines(0);
TextView view1 = new TextView(this);
view1.setLines(4);
mListView.addFooterView(view, null, true);
mListView.addFooterView(view1, null, false);
mListView.setFooterDividersEnabled(true);
Try setting the layout_height of the ListView to match_parent:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#333333"
android:dividerHeight="1px"
When the layout_height is set to wrap_content it might skip the bottom divider:
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#333333"
android:dividerHeight="1px"
Head through the wall approach, but reliable, is to manually add divider as a footer view.
ListView myListView = (ListView) view.findViewById(R.id.my_list_view);
myListView.addFooterView(getInflater().inflate(R.layout.horizontal_divider, myListView, false), null, false);
myListView.addFooterView(getInflater().inflate(R.layout.the_original_footer_view, myListView, false), null, false);
Where the layout file would look like this:
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="1px"
android:background="?android:attr/dividerVertical" />
This approach can be used to add the divider easily even after the last footer, regardless it is selectable, enabled or anything - it just stays there.
Note the height is 1px rather than 1dp. Though against all recommendations, at least at the device I tested this gives the same divider height as ListView, while 1dp does not.

Categories

Resources