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.
Related
Here is a screenshot of my app.
The circled area is a RecyclerView with a TouchHelper so you can swipe left to delete items in the list.
Each item in the recycler list is a CardView that contains a linear layout and the text is a simple TextView.
I want to be able to scroll the text within each of the TextViews as well as be able to swipe to delete, but only swipe to delete is working.
What do I need to do to enable scrolling of these TextViews, which have more text than can fit in the 4 lines?
Here's some of the relevant code and layout.
// Initialize comment list adapter
commentAdapter = CommentListAdapter(this)
binding.comments.adapter = commentAdapter
binding.comments.layoutManager = LinearLayoutManager(this)
binding.comments.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))
val itemTouchHelper = ItemTouchHelper(SwipeToDeleteCallback(commentAdapter, (ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT)))
itemTouchHelper.attachToRecyclerView(binding.comments)
Here's the XML for each of the "comment" TextViews. Note how I'm setting a vertical scrollbar, as most of the Internet recommends. And I've limited the number of lines to 4 in order to keep each individual item smaller.
My limiting of the number of lines to 4 in the TextView is perhaps not what the system expects, since normally the entirety of the text would be displayed within each RecyclerView item. And indeed it works that way if I remove the maxLines limitation.
<TextView
android:id="#+id/comment_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:maxLines="4"
android:text="#string/comment_text" />
Wrap the TextView inside a ScrollView
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/comment_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:maxLines="4"
android:text="#string/comment_text" />
</LinearLayout>
</ScrollView>
I have wrapped an activity in an scroll view like following.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<include layout="#layout/content_form" />
</ScrollView>
I have around 15 fields in the content_form layout, the issues is that the last item in content_form layout is attached with bottom.
I need to add a margin below the scroll view, i have tried giving margin to scrollviewand the last item of content_form field, but nothing is working.
I need to know how to add margin at the bottom of page when using scroll view.
If you want the scrolling margin to be within the content, it would be best to add it to content_form. You should be able to accomplish this by either adding paddingBottom to your parent container in that layout, or layout_marginBottom on your last view aligned to the parent bottom.
This make padding under the last item in scroll view. may be good for you
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:paddingBottom="80dp"
android:clipToPadding="false"
android:layout_height="match_parent">
You can either use Space or View for the purpose like
<Space
android:layout_width="100dp"
android:layout_height="match_parent"/>
Or,
<View
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
Here, you need to give padding, not margin.
Try giving padding to the ScrollView.
I've had issues with ScrollView being ill-behaved when it's direct childview is not a LinearLayout. So please try LinearLayout as direct child of your scrollView and place <include> layout inside LinearLayout.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
... your layouts go here ...
</LinearLayout>
</ScrollView>
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
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?
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.