remove bottom divider of a android ExpandedListView - android

So I am trying to remove the top and bottom (or header and footer if you will) dividers from the listsviews within each group of a ExpandableListView. I saw this link (Remove the bottom divider of an android ListView) but that does not seem to work with the ExpandableListView. Does anyone have a way to do this within code or XML markup? I can disable them all together and do it with in the item layout, but since I share that with nother list I do not really want to go that route unless I have too.
I am targeting Honeycomb (3.1).

Have you tried setting the android:childDivider xml attribute to 0px?

Related

Removing default padding in listview items within Android studio

Can someone provide me with any insights on how to remove the default padding around a listview item? I have provided an image with arrows indicating what padding I am talking about.
You need to create custom a custom layout file for your list items. And a custom adapter. Then you can control all the appearance.

Removing Dividers and Adding Space between Expandable List Groups Android

I'm working on my theme in android and am having a heck of a time getting my Expandable List Views to look right. Here is my desired effect.
Collapsed
Expanded
So I primarily want the space between each List Group. And since android also adds those dividers I want to get rid of all of them.
Here is what I'm getting without trying any trickery.
Collapsed
Expanded
I assumed the best way to get my desired look would be to put a margin on the list group layout xml file but I get end up getting this. It does not put a spacer on my group indicator and also puts the space between the group and the child which I don't want.
Collapsed
Expanded
Any help or a push in the right direction would be greatly appreciated. Thank You!
You can use these properties of listview dont know if it will solve your problem though:
android:divider="#FFF" // same as your background
android:dividerHeight="0dp"//for not showing one
android:divider="#android:color/transparent" //setting divider to transparent
android:dividerHeight="-1dp"//setting negative height also works but only on relative and linear layout according to google engineers but I have tested it to work in many scenarios use this with care

Which layout and control is suitable for sliding window where icons will be appearing in Android

I am developing an application where i need icons to be floating on my panel. I am not sure which control and layout will be suitable for this. I am attaching an image to make you understand what i mean. I want the same two column icon based layout. And if i will scroll down it should be in a sliding way and scroll down. Please let me know which layout and control is suitable for sliding window where icons will be appearing in Android. I am new bie so i am sorry if its not a good question.
If you have a fixed number of items, you could simply use LinearLayouts (with a ScrollView as the root view of the layout). If you have a large number of items or you don't know in advance how many items you will have, use a GridView (and do not place it inside of a ScrollView).

Hiding the Header view in ListView

I'm trying to add a header view to my list, and hide it all the time unless we scroll to it (like the pull-to-refresh mechanism). The problem is: if the list is not tall enough to fill the screen - the header view is shown on top of the list.
Is there a way to hide it, and make it visible only when we scroll to it? I've been trying a lot of stuff, but I can't figure out a good and simple way to do so.
Thanks
Here's a blog post describing a simple way of hiding and showing the header view.
The idea is to to put the content you wish to hide in a LinearLayout that wraps it, and hiding the content only. That way, the wrapping LinearLayout will collapse when its content is hidden, resulting in a headerView that is technically still present, but 0dip high.
Note: If you would try to hide the content without the enclosing layout, you would be left with unwanted space in the header view.
An example layout with a spinner representing the content:
<LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ProgressBar
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Then you can hide the spinner (content) as follows:
spinnerLayout.findViewById(R.id.spinner).setVisibility(View.GONE);
You could look into ListView.setOverscrollHeader() or ListView.setOverscrollFooter(). Is this the behavior you are looking for?
If not, could you post some code showing what you have so far?
EDIT:
Ok so I looked into Overscrolling headers/footers and you're right, I don't think that's what you want at all.
Instead you should probably look into the Pull to Refresh mechanism from the Twitter app that others have tried to emulate. You can look into the answers from this question.
The most promising answer seems to be the custom ListView written by Johan Nilson, the code for which can be found here:
https://github.com/johannilsson/android-pulltorefresh
EDIT #2:
I took a look at the PullToRefresh custom ListView and what you want to do is probably possible, though not necessarily easy. Allow me to explain.
The PullToRefreshListView is essentially just a hack that exploits the optional Header in standard ListViews. The hidden "Pull To Refresh" that you see is really just the header of the ListView. When the list is displayed, this line is executed:
setSelection(1);
This scrolls the list to the first item on the list, effectively hiding the Header. When the List is short enough to be displayed entirely on screen, no scrolling is necessary, hence the "Tap to Refresh" button.
When this "Tap to Refresh" is visible, the pull to refresh mechanism is disabled, but it's easy enough to fix that. The pull to refresh effect is accomplished by increasing the top padding of the header view so that it appears that you are pulling the list down (when really it's more accurate to say that the Header is pushing the rest of the list down).
The amount of padding added is controlled by the applyHeaderPadding() function on line 199 of the source code. In that function there is an if statement on line 220 that only applies the padding when the list is in RELEASE_TO_REFRESH mode:
if (mRefreshState == RELEASE_TO_REFRESH)
{
//Some code that eventually adds padding to the header...
}
If you eliminate this condition or change it to apply padding no matter what mode you are in you can drag to refresh even if the list is short and the header says "Tap to Refresh"
if (true)
{
//Some code that eventually adds padding to the header...
}
However, this doesn't exactly create the effect you're looking for. If the list is short, you can drag it down to refresh, but the "Tap to Refresh" header is still shown. Now the problem is "How can I hide the header until the dragging motion begins?" This is a difficult problem on it's own, with several Stack Overflow questions dedicated to it.
If you want a header, you must add it BEFORE you set the adapter for the ListView, otherwise you get all sorts of errors.
I had some success with this, but I haven't come up with anything stable, because my solution is a kind of nasty hack on top of the already hacked PullToRefreshListView. I set an empty FrameLayout as the header and added the original pull to refresh header to that Frame Layout. Then, as I dragged the list, I edited the height in the LayoutParameters of the Frame Layout to grow and shrink much like the padding had originally. It sort of worked, but would eventually force close, and I haven't figured out why yet.
Anyway, if I get it to work I'll post the code, otherwise someone wiser than I might propose a solution based on the info I just provided.
Here is a solution for the current PullToRefreshListView (updated November 4, 2011):
https://github.com/johannilsson/android-pulltorefresh
based on the Hiding Header Views article:
http://pivotallabs.com/users/joe/blog/articles/1759-android-tidbits-6-22-2011-hiding-header-views
1) Copy pull_to_refresh_header.xml from the library's res/layout to your app's res/layout.
2) Edit your app's pull_to_refresh_header.xml. Wrap topmost RelativeLayout in a LinearLayout and then wrap the LinearLayout in a RelativeLayout again. Why? Topmost layout must be RelativeLayout because that's what's expected in code, second level layout must be LinearLayout because that's the only layout that collapses with View.GONE. Third level layout must be the same as original top-level RelativeLayout (except id) to preserve look.
3) Preserve same id on top RelativeLayout (pull_to_refresh_header), give second level LinearLayout an id of your choosing, give third level RelativeLayout another id (pull_to_refresh_header2 for example).
4) Move all padding from the topmost RelativeLayout to the second RelativeLayout.
5) In your code use findViewById and your LinearLayout id to set visibility to View.GONE. The LinearLayout will collapse, and if you moved all padding values appropriately to the inner RelativeLayout the header should take no space at all.

ListView Scrolling

I have three items in a ListView. The reason I have chosen the ListView is so I can use a Divider and a List Selector on these items.
However I do not need/want the scrolling aspect of the ListView. Ie. When I select/drag an item from the list, I dont want it to scroll..
Is it possible to disable this somehow? Or will I have to add the items using a LinearLayout and find another way of using a list divider and selector?
I'm not sure how well this will work for you, but you can disable overscroll (available in android-9 and above):
listView.setOverScrollMode(View.OVER_SCROLL_NEVER);
and then also hide the scroll bars:
listView.setVerticalScrollBarEnabled(false);
After this, if your list does not exceed the screen size then it shouldn't be able to scroll.
If you dont need to scroll listview, you can add the list item to a linear layout as well you can design it also through xml file.
And for put a DIVIDER to it just take a "View" widget.
Put it height 1 dip and width fill_parent. You can give color to this view through background color.
Try it. i have done it many times.

Categories

Resources