I have a ListView inside an AppWidget. Each row of the ListView has a custom layout, AppWidget specifies a minHeight, as required. The problem is that ListView exceeds the dimensions of the AppWidget, and some rows simply hang below the widget boundaries.
I have tried everything I could think of, fixing the height of ListView, using match_parent and/or wrap_content or rows and ListView, but I have not been able to fix this.
Has someone else faced this problem? How do I make the ListView fit inside the widget boundaries and scroll, instead of rows getting outside the boundary?
Well I have root-caused the issue, and I am to blame here, at least partly.
I am asked to use a custom background for the ListView, and the 9-patch I received had a shadow drawn below the 'content' background. Android used the whole png for drawing the background, lending an appearance of 'one row hanging off the content' appearance to the widget.
I verified this by using a solid color as background - it extends properly to cover entire ListView.
My learning:
1. The minWidth and minHeight attributes for the widget are exactly what they say; Android WILL give more space to the widget if it can. :)
2. You've specified "minimum" width, and your actual width is being determined by the width of a child View. Given that such a case could be common, setting the top-level layout width and height to wrap_content in the widget's main view seems a reasonable thing to do.
Related
So i'm trying to hack away an issue I'm having. To reach my goal of not having views i set the height of the view, in the adapter, to 5 pixel. To make sure they're being drawn i also set the background color to a whole different one.
When calling getChildCount in the custom listView It doesn't seem to count the smaller views even though they are clearly visible and on the screen.
I'm wondering if the listview is miscalculating the number of views in the screen due to the difference in height and if so how should i fix it.
I have a widget with 2 oval buttons (defined in a XML file). At the moment, I've hard coded the width and height of the button to 180dp, but this poses problems when making the widget smaller.
Is there anyway I can set the width and height of the button to scale as the widget size is changed?
Resizable widgets are preferred feature for collection widgets
such as those based on ListView or GridView. App Widget Design Guideline
So for your purpose it's better to use different layout if your widget gets resized. On Android 4.1 and above you may use onAppWidgetOptionsChanged() method to load different layout when your widget is resized. See these answers for more information:
How to use onAppWidgetOptionsChanged() in a widget?
define widget's behaviour/layout for resize and orientation change
I want to stretch the row of a GridView to match the height of the screen in Android.
How do I do this?
You are in control over your row heights, by virtue of what you put in
them. Since your cells appear to have more than one widget, they are
presumably wrapped in a LinearLayout or something. Set your
LinearLayouts to be some specific height, and the rows will all be
that height.
Personally, I think you should be resizing your images if you are
going to have text above and below each image on a per-cell basis.
With the Reference commonsware link
I have multiple custom views rendered on my screen in RelativeLayout using LayoutParams. Now first time user touches on view it increase it's size, after that when user once again clicks on that view, that view should get disappear. Now the problem is when a view gets disappeared other views on screen changes their size and location. By debugging I found that this happens when I pass dynamic values as width and height in LayoutParams. If I go for static then all works good. But then I'm not able to increase the size of view. How can I solve this? I also tried changing View.GONE to View.INVISIBLE but that also doesn't help.
I create all views in code and place them on screen. In my xml I don not have any view entry. I do this because initial size of views should be random. So I create view and assign him initial size in LayoutParams(width, height) and then use topMargin and leftMargin to place them at various positions on screen. More details can be found here: Custom object click issue in android
Best guess without seeing any code... It sounds like you are using layout_weight, and if a view is removed, the other views with a layout_weight will expand to fill the now available space.
I have a list view which is rendered each time with a different list of items, with variable height.
What I want is to set all the Views in the list view to the same layout height according to the view with the highest layout_height, when setting it to layout_height="wrap_content" for each View.
Also I would like to apply min and max values for the height.
So if I define min=30dp,max=100dp, and the biggest View is automatically rendered with 70dp
all Views in the ListView should be set to 70dp.
I have no idea how to go about it, expect for calculating in the code the max view height values, and setting them to all views, but this doesn't seem very elegant to me, especially as I need to translate it to DPs in the code.
Any simpler ideas?
Your right what you try to achieve wont be as pretty as the regular way, but it'll work ;) usually you would decide height beforehand and then go with it :)