I need to show embeded slider (marked green) inside of the list of recyclerview items, like on image below:
I am thinking that I need to change something in my recyclerview layout manager, but I have no idea what exactly and guess it is quite complicated. In addition I am using FlexboxLayout here.
So, could you please help me with the selection of the best approach of solving this problem?
You can inflate different view for that position , since you're inflating a different layout there .
This answer will help :- RecyclerView with multiple view type
The basic gist is to use the getItemViewType and return a flag , say 1 for the first red box , 2 for the second and 3 for the third and inflate layout on depending on the viewType param ( in the signature )
you can resolve it easily to make the layout like this.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/recycler_view_item_background_color">
<!-- Red layout-->
<LinearLayout
android:id="#+id/red_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/item_performance_list_padding"
android:orientation="vertical">
<TextView
android:id="#+id/performance_date_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""/>
</LinearLayout>
<!-- Blue Layout-->
<LinearLayout
android:id="#+id/blue_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/text_item_divider" />
</LinearLayout>
you can show or hide the blue layout for every item according to your need.
LinearLayout blueLayout = (LinearLayout) findViewById(R.id.blue_layout);
blueLayout.setVisibility(View.GONE); // hide
blueLayout.setVisibility(View.VISIBLE); // show
Related
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 .
As you can see on an attached image I'm having a sort of triangle shadow at the right side of my cards down in the list.
I have elevation set to 0 for all three:
app:cardElevation="0dp"
card_view:cardElevation="0dp"
android:elevation="0dp"
This happens to all my lists. What am I missing?
You didn't post complete layout source, but I had the same issue and I assume the cause was the same. I had a similar list of items, each row being a custom view which extends LinearLayout and inflates some custom layout (let's call it row_item.xml). The list layout looked something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.example.android.RowItem
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<com.example.android.RowItem
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
The RowItem layout (row_item.xml) looked something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:elevation="10dp"
android:outlineProvider="bounds">
...
</LinearLayout>
The problem is RowItem being LinearLayout alone and inflating row_item.xml with the following code:
LayoutInflater.from(context).inflate(R.layout.row_item, this, true);
This actually wrapped the LinearLayout with elevation by ANOTHER LinearLayout, creating a layout similar to this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:elevation="10dp"
android:outlineProvider="bounds">
...
</LinearLayout>
</LinearLayout>
Setting elevation on the LinearLayout wrapped by another LinearLayout caused these weird shadows. The solution is setting the elevation on the outside LinearLayout. Even better solution is getting rid of the double layout by replacing <LinearLayout> by <merge> in row_item.xml and setting elevation programmatically inside the custom view's code.
In case you are not using a custom view but are having this problem, you are probably not setting elevation on the outer most container of your item.
I have read https://stackoverflow.com/a/2620252/779408 and know how to add a header to listview. But this header is not fixed when the user scroll down the list.
How can I fix the place of the header of ListView when the user scroll the list and make it visible always on top?
The better way is set the header statically in a separated layout (ouside your ListView). An example that illustrates this could be:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="#+id/YOUR_HEADER_VIEW"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
You have to replace the View with your header's view.
I hope this solve your problem.
maybe just put your header out of the list. make the view to stick on top of the list and work on the design so it looks like it is inside the list.
I searched already but unfortunately found no real solution to this. I have added a footer to a listview with:
View footer = getLayoutInflater().inflate(R.layout.listfooter, null);
listview.addFooterView(footer);
The xml for the footer looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#FFFFFFFF"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:background="#ee222222"
>
<TextView
android:id="#+id/info"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Test Test Test"
android:layout_alignParentBottom="true"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
It does display a footer only as a single line
I change the number of rows in the list dynamically but I want the footer to always fill the rest of the listview if there are not enough items in it.
How can I do this?
Edit: I added an image, the left is how it is right now and the 2 on the right is what I want.
I can say the best solution can be for this problem is.
1) Create a XMl layout which must have hierarchy like this.
<Liniear Layout>
<ScrollView>
<LinearLayout>
<ListView>// add your list data here.
<\ListView>
<TextView><TextView>// for footer text
<\LinearLayout>
<ScrollView>
<LinearLayout>
Please let me kno if anything, I hope this approach will work as I tried it myself.
My situation is following. I have one Activity that contains three main parts. At the top of this activity there is an tools panel with two ImageButtons. At the bottom of the activity there is also tools panel similar to top. Main component of this activity is at the center of the screen which is LinearLayout that contains 3x3 ImageButtons grid. To get the context I quickly describe purpose of these grid buttons. This 3x3 grid describes states of this buttons (lets say toggle button and its states are on/off) for particular day. So for one day you have one set of 3x3 and these have its own state for particular day.Now what I trying to achieve is to have functionality which allows user to scroll between grids or dates respectively. My idea is to have ViewFlipper as the main component of the activity (instead of LinearLayout) and one or more grid of buttons. This is what I already have. I am able to switch 3x3 to another 3x3 (with states) for another day. For this I simply copy/paste my 3x3 grid XML definition and put this as children to view flipper (x-times).My idea is to have one definition of 3x3 and reuse it x-times like some kind of template so I will be able to say "I want to have another 3x3 with so and so states for this day and I want it to add this as next child to ViewFlipper".For this purpose (to have component of 3x3) I simply made class which extends LinearLayour and within it I want to generate/reuse 3x3 definition for buttons. Sure I am able to do it by java code in this new class but is some way to do it with reusing of xml (which is better to maintain and to read)?I tried to use LayoutInflater but this is probably not what I am looking for.
Thanks in advance
Edit
Here is code for main layout with flipper
<ViewFlipper android:id="#+id/view_flip"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#FF0000">
<!-- Here goes 9x9 cubbie layout programaticaly -->
</ViewFlipper>
To this fipper I adding view with this layout (this code is assigned via LayoutInflater).
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/background" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:gravity="center">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="vertical">
<ImageButton android:id="#+id/life_att_1" style="#style/AttributeButton" />
<TextView android:id="#+id/life_att_text_1" android:text="test"
style="#style/AttributeText" />
</LinearLayout>
...
</LinearLayout>
...
</LinearLayout>
EDIT 2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/background" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:layout_weight="1" android:paddingLeft="16dip">
Only way I found here is to add paddingLeft attribute to wrapper LinearLayout (please refer to EDIT 2). I do not think that this is right solution but only solution I currently found.