Android: ListView column sizing to first item - android

I have a ListView inside of a HorizontalScrollView which I'm using as a small panel overlaying a fragment. It all would work as expected if the longest item were the top item. When the shortest is, the ListView's width takes on the width of that item and then there's no horizontal scrolling. The rest of the items are just cropped.
Here is the pertinent portions of the layout:
<HorizontalScrollView
android:id="#+id/vendorListContainer"
android:layout_width="180dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#50FFFFFF"
android:visibility="gone" >
<ListView
android:id="#+id/vendorList"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</HorizontalScrollView>
I'm using the android.R.layout.simple_list_item_activated_1 as the item layout. Should I be using a custom layout with some special options chosen to fix this? I thought of just padding all the strings, but that's a hack I'd rather avoid. What am I doing wrong?

Related

Second list view not expanding in linear layout fragemnt

My linear layout having two list views, when i add items in second list view, its not expanding. its getting scrolled automatically,
i have used match_parent in my linear layout, even though the second list view (getting scrolled instead of expanding) or the linear layout is not expanding.
Can anyone please help me to expand the list view or the linear layout.
problem in linear layout or the second list view?
but the first list view expanding properly.
fragment_one.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:descendantFocusability="blocksDescendants"
android:padding="10dip" >
<ListView
android:id="#+id/list_nation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="#B29090"
android:nestedScrollingEnabled="true">
</ListView>
<ListView
android:id="#+id/list_regional"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="#4A9C67"
android:focusable="false"
android:nestedScrollingEnabled="true">
</ListView>
</LinearLayout>
When you add multiple scrolls in a single screen it always shows problems. Because they conflict with each other.
There are two solution for your problem.
If you want to keep your each listview to take half screen then add "weightsum = 100" in your main linear layout and set weight of both listviews to "50".
If you want your first list to scroll till end and at the end of first you want the second one to start scrolling, then calculate the height of your lists on run time and assign the calculated height to your listviews. Check this: Android: How to measure total height of ListView

Android ListView cutting off items wider than the first item

I have a Listview inside of a HorizontalScrollView. The listview holds file paths, and the horizontal scroll view is intended to eliminate the need to wrap the longer paths.
Everything is working exactly as desired with the exception that any items longer than the first item in the listview are being cut of at the length of the first item (whatever the width of the first item, none of the other items will scroll past that width).
Here is the section of the layout that is giving me trouble:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/layoutListView"
android:orientation="vertical"
android:layout_below="#+id/spFileTypes">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/lvItems"/>
</HorizontalScrollView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text=""
android:id="#+id/tvStatus"/>
</LinearLayout>
Here is a screenshot of the issue:
The image is scrolled all the way to the right. The third item is cutting off ".php". I have tried this with long and short file names, lists of many (upper double digits) and lists with just a few, in each case, it seems the width limit is dependent of the width of the first item.
Whenever the lists changes, it always limits its width to whatever the first element is.
The desired behavior is to have it match the width of the widest item.
I've googled my heart out, dug through the official documentation, and I'm stumped. Any help is greatly appreciated :)
Instead of wrapping the ListView in HorizontalScrollView, try this:
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"/>

RecyclerView fit item to bottom

I have a RecyclerView matching the height of the parent layout.
I need to have an item there to function as a footer. Doing this is not the problem when there are a bunch of items in the list.
The problem is to get it to stick to the bottom when there are a few items and it's not enough to enable the scroll. So, if I have, say 1 item plus footer item, how can I display this item at the bottom of the RecyclerView?
Try using android:weight property. Or if you're using RelativeLayout align the footer to the bottom of the parent view
try this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/places_recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<YourView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
YourView is the view where you will actually add the view for your funcionality. Even if there is no items or there is, it will always be on bottom.

Force an ExpandableListView to move other items down

My layout is a ScrollView with some TextView and other controls and also an ExpandableListView.
What I want to do is When Expanding the ExpandableListView the controls which are below it move down and again upon collapsing, all the controls move up and only Group of Expendables become Visible.
The problem is when using wrap_content for expandView's Height the expanding of it shows nothing and just the indicator (little arrow) shows that it's expanded, and when explicitly use some numbers eg. 200dp, the lowest items of expandView not shown. (Because of using two Scrolling widget together).
Here's my simplified layout.
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="HardcodedText" >
<LinearLayout>
//some controls
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ExpandableListView
android:id="#+id/lstDrugs"
android:layout_width="match_parent"
//HERE is the point that wrap_content only shows the groups header
android:layout_height=**"wrap_content"**
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:divider="#drawable/dividergradient"
android:dividerHeight="2dp" >
</ExpandableListView>
<Button
android:id="#+id/btnAddDrug"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/lstDrugs"
android:text="Add" />
</RelativeLayout>
</LinearLayout>
I've just found my answer in this thread.
The problem is with using List inside ScrollView. To handle it you should use a layout other than the ScrollView (eg. LinearLayout) and add other widgets as Header and Footer of the list. This would enable the scrolling of the view and also expanding of the List.

ListView scrollbarStyle with margin/padding

Hopefully a simple one.
v4.0.3
I have a ListView and want to leave a margin of 10dip right and left.
The content is easy of course, but I want the divider line to have a 10dip margin right and left too.
If I add android:PaddingRight or android:layout_marginRight to the ListView or the LinearLayout which contains the ListView then this works of course, but the List scrollbar which appears down the right hand side as you scroll the list also moves in by the padding/margin distance.
I want the scrollbar indicator to remain.
I've tried all the android:scrollbarStylesettings.
Can do easily
<ListView
android:id="#+id/lvDonorDetails"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#drawable/list_divider"
android:dividerHeight="1dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:scrollbarStyle="outsideInset"/>
Or
<ListView
android:id="#+id/lvDonorDetails"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="1dp"
android:padding="10dp"
android:scrollbarStyle="outsideInset"/>
You may create new scrollbar thumb drawable what do you want about scroll drawable margin and padding.
Use these attr
android:scrollbarThumbHorizontal="#drawable/your_drawable"
android:scrollbarThumbVertical="#drawable/your_drawable"
I had the same problem of scrolling the list view. putting inside a scroll view is limiting the list view to load only one row when we want to load the list dynamically,but at last got the solution :
include
android:scrollbarAlwaysDrawVerticalTrack= "true"
and
android:fadeScrollbars="false"
properties inside the ListView Tag.
To have an equal margins (around and between) ListView items without having the scrollbar overlaying the ListView items, you can use the following code:
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_gravity="center_horizontal|top"
android:dividerHeight="10dp"
android:divider="#android:color/transparent"
android:padding="10dp"
android:scrollbarStyle="outsideOverlay"/>

Categories

Resources