I'm using a custom Adapter to fill a ListView. ListView items contain a sort of icon strip - a various number of icons related to the item. My icon strip is a horizontal LinearLayout. What I would like to do is to stop adding icons to LinearLayout when they don't fit in it anymore and create a new LinearLayout instead and icons to it. So basically it's a multiline grid of icons. I'm using API lvl 8.
The problem is that in my Adapter's bindView function all layouts are not measured yet and report zeroes as width, height, measuredWidth and measuredHeight.
I do not know how to proceed so any help is welcome.
Related
I want to add dividers to listview with specific width, like the foursquare app on tips list:
I don't know the proper way to do it, i tried adding a line on bottom of each item view, but the last item have a divider too, i know its a wrong way.
Is there any way to make the divider width the same of the text content?
You can set any arbitrary Drawable as a divider by calling ListView's setDrawable() method. If you know the width of the content you intend to display you can use that knowledge to make an appropriate graphic.
Also be aware that you will need to call setDividerHeight() if the drawable does not have an intrinsic height.
I am creating an AppWidget that allows users to skin the widget and download from a list of widgets online. I would like to allow skinners to offset the position of the icons vertically.
I initally tried calling offsetTopAndBottom on the LinearLayout that holds the icons, this is not allowed as its not supported with RemoteViews.
I then had an idea of using 2 Views inside a LinearLayout (on top and below the icon Layout) to "squash" the icons towards the bottom (if the height of the top layout was set to > 0).
When I tried to set the height of these views: -
views.setInt(R.id.iconMarginTop, "setMinimumHeight", offset);
it also complained that it wasn't supported with RemoteViews
Any ideas what I could do to acheive this offset?
Thanks for your help!
I don't think this can be done. The best thing I can think of is to have multiple layouts with the view at different positions. This might not suit every situations though
I have ListView. I would like to fill each row of ListView with a background from left to x% ...
So what I want is:
Item - 50% of background is colored
Item - 20% of background is colored
Item - 90% of background is colored
Is it possible to this?
Thanks for the answer!
As far as I know this is not possible out of the box. But I think you can archive is with a little trick.
You have to define a custom view for you rows. This view has a RelativeLayout as root element on which you can set the background color you want to have.
You then add another view element to the root element which covers a part of the root element. The background color of this element should be set to black and should be aligned to the right. The RelativeLayout provides many attributed you can use to arrange the elements.
Furthermore you have to write a custom adapter which handles the creation of the single list items views. When you override the getView() method where the view elements for each single row are created and inflated to the ListView, you calculate and set the width of the "cover"-element in such a ways that it covers a part of the root element.
The difficult part will be to calculate the width of the cover-element so that the rest of the root element which is not covered and still visible correspond to the percentage you want it to have.
Here you find a short tutorial about how to implement a custom Adapter with a custom view for the list items.
It is possible by the concept of custom layouts. This is a good article for to learn more. Also, I think you need to go through the NotePad tutorial in Android official site.
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.
i was requested to make in android a view that groups several items like checkboxes or text views in vertical rows, separated by transparent dividers while the background is with a certain alpha level and the edges are round.
I thought of two solutions and i hope for some feedback on good\bad or other solutions if you got'em.
just use regualr linear layout but have a single style A that uses a 9 patch as background, includes padding,margins and whatever i need to make it look like what i want. i then create another style A.up and A.down that represents the upper most and lower most items that will use a different 9-path with round corners.
inherit from linear layout, in the onMeasure and layoutChildren add to all the children some kind of space between them, i can create new attribute for it that can be customized in a style. i can override the dispatchDraw to paint the background for each view before it draws so i can paint my round borders, my only demand will be that each View added to this layout will have to be with transparent background.
So what do you think ?
Eventually i decided to use a List with customized divider.
It looks good, however a list got a very nasty bug when it comes down to items with states like buttons and clickable textViews,
you get no focus for the item and don't see the ornage bar
you don't seem to get the evnets flowing to the children of the View in the list.
I'm notsure how to resolve that one, i've seen numerous mails about it in the developres mailing list and here, most saying don't put statefull objects in a list.
So it mist not be the solution for me.
Nest thing i'll try is extending the normal layouts to have a bar in their bottom and use regualr linear layout with round corners drawable.