Custom divider in RecyclerView - android

I have a custom layout for my recycler view with an image view and a text view(in a horizontal linear layout). I needed a custom behaviour for my divider - divider should show only under the textview area and not the image view area. For example, whatsapp's chat list view - link
When I use the default DividerItemDecoration, it creates a divider across the view.
How do I achieve a custom Divider which spans only certain views?

I solved this here - https://gist.github.com/shiladitya-bits/1444002568de9f02ce3d
View avoidView = child.findViewById(avoidResourceId);
if(avoidView != null){
width = avoidView.getWidth();
}
mDivider.setBounds(left+width, top, right, bottom);

Related

How to add specific start margin , end margin and margin between items in a recycler view

I need to create a recycler view in which the items spacing should be in below format:
Each row should have 3 items.
The left margin of 1st item should be 16dp
Margin between each items should be 10dp
The right margin of last item should be 16dp
The margins are fixed but items should stretch to occupy the width to maintain margins.
How can i add the spacing constraints should grid layout be used or will work for linear too?
Try following things
In your recycle item use width match_parent and give a 10dp margin to the parent layout. (In your Adaptor Item Layout)
In your recycle view provide a 6dp margin. (In your XML having recycle view)
For show items in Grid obviously you need to use GridLayoutManager with your Adaptor.

ConstraintLayout baseline alignment support for custom view

I had created custom view based on LinearLayout with two TextView, i placed it in ConstraintLayout but i can not align other view to baseline of that custom view. Am i able to define baseline in my customview?
solved by override View#getBaseline method
i had set it to getBaseline of one of child view

Expand width of multiline textview below another horizontally aligned view if space is available

One multiline textview and an another custom view are aligned horizontally in a linear layout. Height of custom view is 100dp. What I want to achieve is to expand width of lines of multiline textview which are below custom view to match parent.
This is a rough sketch of what I want to implement.
Is there any way to achieve this?

AdapterView (TwoWayView) margin of item

I'm using the TwoWayView library : https://github.com/lucasr/twoway-view to try and implement a horizontal ListView of sorts to overhaul what I had before. (HorizontalScrollView with a horizontally oriented LinearLayout that I add views to)
I want to have a margin before the first item, so there's a blank space at the left when the View is first created. But when scrolled, the blank space would be scrolled and disappear as well. When using a normal ListView it is essentially a HeaderView that I want.
When I implemented the scroll using HorizontalScrollView, I simply programmatically checked the first item and added the margin, which worked since its parent was LinearLayout and accepts margins. But I cannot do this in the getView() of the adapter used for this AdapterView since its LayoutParams do not inherit ViewGroup.MarginLayoutParams
I've also tried setting clipToPadding="false", but the views gets recycled too early, which is unacceptable since the padding I need is noticeably big.
Is there a way to achieve this behavior without moving all the HeaderView code from ListView into the TwoWayView library?
You can try something like this:
on getView(int pos, View convertView, ViewGroup parent){}
{
if (convertView == null)
{ ... }
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT , ViewGroup.LayoutParams.WRAP_CONTENT);
/// To set your margin, you just need to test the position :)
params.setMargins(left, top, right, bottom);
viewHolder.LinearLayout.setLayoutParams(params);
}
Hope this would help you.

Android - show footer divider but no list row divider

I have a list view which has a footer.
It displays numbers and at the bottom is the total.
I want to be able to show the rows without a divider between them. OTOH I DO want a divider before the summary row.
Is there any easy way to do this?
You can set android:dividerHeight to 0 in your list.
Then use custom layout for footer in which you add divider by yourself. For example, that can be a TextView with no text, android:layout_height set to 2 and android:background set to some color.
When you have custom layout for the footer, just add divider on top of it. It can be for example View of hight 2dp and different background color.
I had to do this programatically, since setting android:dividerHeight="0dip" in the XML didn't work for me:
getListView().setDividerHeight(0);

Categories

Resources