I want to achieve this design shown below. All I can think of is having a LinearLayout as parent layout with android:orientation="vertical" and add listViews with horizontal scroll dynamically inside the linear layout, but it seems very inefficient solution.
What can be the best possible approach to achieve this UI? Any suggestion will be highly appreciated.
If I were you, I will create a RecyclerView witch adds the rows of the Textview and another recyclerview.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvCards"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
The second recyclerview will contains columns of those cards. Of course the second recyclerview will contain the LinearLayoutManager like that:
LinearLayoutManager linearLayoutManager
= new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false);
I'm not sure if that solution will be the most efficient one. I would like to read more comments to find a better solution, if it exists.
Related
I'm new to Stack Overflow. I'm looking forward to making a calculator in the XML and Kotlin combination. I'm aware I should use a TextView or EditText above and RecyclerView below but "how to add 3 buttons in one row in RecyclerView StackOverflow". in all the tutorials I see they show only one element per row. but I have to add 3 elements. I tried to google search "how to add 3 buttons in one row in RecyclerView StackOverflow" but got no good results.
I'm well aware of the working of RecyclerView, so I don't want full code. I just need which part when altered gets me 3 buttons in RecyclerView.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/calcTv"
android:layout_marginTop="9dp"
android:textSize="36dp"
android:textAlignment="center"
android:text="5+4"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_below="#+id/calcTv"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Along with the above code, I have a RecyclerView adapter and XML for layout inflating.
Sorry in advance if the question is not clear and for my way of asking.
Add layoutManager and spanCount attributes to your RecyclerView:
<androidx.recyclerview.widget.RecyclerView
android:layout_below="#+id/calcTv"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:spanCount="3"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"/>
layoutManager for making the list grid or linear
spanCount is the number of columns
I am using two RecyclerView in LinearLayout in NestedScrollView see xml file.
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvData1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvData2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
And i wrote the code animation in onBindViewHolder Adapter class
holder.parentView.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.right_to_left));
And My all code is perfect when i deleted code NestedScrollView then animation is perfect working and NestedScrollView visible then it is not working animation like simple to display all items in row of adapter.
Android guys share your best experience what you did.
Thank You !
Change your coding style, can you make nested recyclerview, I mean, In
one recyclerview put rest of recyclerview. you can create this kind of
recyclerview by using VIEW_TYPE
I have a background image with a long width which I want to be in back of a Recyclerview with 8 item in it(Recyclerview). This is possible only with a horizontal-scrollview which I coded below but Is there any way to not use horizontal scrollview and have a same result?
<HorizontalScrollView
android:id="#+id/HSV"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/back"
android:paddingLeft="2.5dp"
android:paddingRight="2.5dp"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</HorizontalScrollView>
with the above code I have the desired output, but as I remove the HorizontalScrollView The image is compressing in width and loose its shape I want the image scroll as I scroll the recyclerview
That is The picture I want:
![in Background is the aforementioned image and this eight Item are in recycler view and I want as the items finishing the background image is finishing too.
]1
Design like this in layout.And pass layout of card in image to adapter in Android.Set background to Constraint layout ore Recyclerview. When you have Recyclerview no need to add Horizontal Scrollview. Just pass Layout manager as Horizontal
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#color/secondaryColor"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>idget.ConstraintLayout>
I wonder if I have got your query right, so you want your RecyclerView to be scrolling horizontally. I would suggest to use the LinearLayoutManager for the same, so that you can pass the Scrolling constant to Horizontal in the arguments of LinearLayoutManager.
To read about it, please go ahead and read it LinearLayoutManager
And when you get it, just do it like this in you Java Class.
RecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true));
I have this youtube link for you too, if you don't get it what you want. Here you will get the full demo of how to do it, and achieve it. Horizontal RecyclerView
I hope that will answer your query. Thanks :)
I'm facing a tricky situation here and I don't know how to solve this problem.
In my project I have a custom BottomSheetDialogFragment and in the layout a FrameLayout to add or replace Fragments.
Now I have a Fragment and inside I have a RecyclerView with the height:="wrap_content" because I want the BottomSheetDialogFragment only use the necessary space. Everything looks great, the problem appear when I put another view inside of the same layout and set the RecyclerView bellow or above of that view.
The RecyclerView ignores the size of the other view (or views) and always grows to the max screen size, and then it's no possible to see a few elements and even scroll.
I saw a solution, some developers are suggesting to add paddingBottom equals to the height of the view. But in my case doesn't works because I want to have a dynamic solution.
Above I'll share a few images of the problem and GitHub Repository with a sample.
Thanks for your attention!
I've manage to do what you need just need to use this as your fragment_sample.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/rclItems"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<Button
android:id="#+id/btnAddMoreItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rclItems"
android:text="#string/add_1_item"/>
</LinearLayout>
Explanation
Using a LinearLayout gives you the ability to work with weight, and the vertical orientation allows you to place an item below the other. The weight on the recyclerview will increase the height of it as needed until filling the screen. The next item you add would be added to the recyclerview but you'll need to scroll the list to see it
The android developers blog says that :-
The scrolling containers in your bottom sheet must support nested scrolling .
Try changing your fragment_sample.xml as below to make the recyclerview scroll working and to make the add button persistent.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:id="#+id/next"
android:layout_above="#id/btnAddMoreItems"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/rclItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.v4.widget.NestedScrollView>
<Button
android:id="#+id/btnAddMoreItems"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:text="#string/add_1_item"/>
</RelativeLayout>
Note: making bottomsheet layout a child view of CoordinatorLayout will allow you to get the implement BottomSheetBehavior and recieve its transitions callbacks .
I'm developing a endless scrollable list for an android app, using the RecyclerView viewgroup and an OnScrollListener where i add the items after the user scrolled to the last item of the RecyclerView.
Now a want to add a black line in the middle behind the items as kind of a recycler view.
As you see, the items can have different heights.
Whats the best (and most performant) way to archieve this?
You might consider using a layout like the following.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/your_background">
<android.support.v7.widget.RecyclerView
android:id="#+id/your_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent" />
</RelativeLayout>