How to get Android LinearLayoutManager to show partial items - java

I'm trying to create a layout that looks like this:
And I haven't been able to find any examples where more than one card is visible at a time. I'd like the targeted card to SNAP to the center. Can someone please show me the secret?

This link, helped decipher the problem. The trick is this view property called
android:clipToPadding="false"
That and a larger margin than I was expecting. A margin of 10-20dp was not large enough to see the other views in the list, because of the space between the recyclerview items. Once I increased the left and right margin to 80dp I got the effect I was looking for.

I think if you're going to achieve that effect, user LinearLayoutManager.HORIZONTAL Cannot be realized ,use viewpager can realized,I have done a similar effect one year ago,Hope help you

Related

Android Best Practice: Dynamically adding buttons to a ViewPager or Pre-Instantiating Them?

So I have a question about best practice for dynamically creating and sizing buttons within a ViewPager, based on a changing external state.
Essentially, I have a scrolling view and I want my ViewPager to contain a number of buttons of a specific size and count depending on what part of the scrolling view is currently visible.
My question is about deciding the best implementation of this feature, I see two options: would it be simpler to
Constantly create and scale new buttons whenever the scrolling view moves
Make the viewpager itself contain a scrollview and fill it with all of the pre-scaled buttons on app startup. Then, whenever the user scrolls the main scrollview the viewpager's scrollview (which contains the buttons) will scale programatically
Any ideas on which would be the simpler and more robust system?
Not much of an answer but I will leave a comment for ya! Basically you can do it either way, both aren't to difficult to accomplish, however I would probably go the dynamic route because it will always scale correctly. Doing a set amount will only work until devices become larger, or if you are targeting tablets or tvs then it will start to become extremely messy in the xml file for the layout. Dynamically adding also gives you far more control and saves time later on, you can simply change a number and have 100 more then going through and manually adding even 10. Hope this helps!

Implementing a list that is both vertically & horizontally scrollable

I have a question related to Android app UI implementation. The UI I want to implement is very similar to the Slideshare app UI, which I've attached below:
Apologies for the size of the image. But basically I want to implement a vertical list, and each item within the list is another horizontal list of sub-items.
My current plan of approach is implementing a vertical RecyclerView, and then implementing each item of the list as a horizontal RecyclerView (basically a 2-Dimensional RecyclerView).
Am I on the right track here? I apologise I cannot provide any code because I am still in the design phase. I do not want any code solutions but rather a guide or small tips as to how to approach implementing such UI.
Thank you for your time reading this question. Any tips would be highly appreciated!
You can use TwoWayView library to implement this scenario for bot horizontal and vertical listviews or you can use RecyclerView.
TwoWayView Library: https://github.com/lucasr/twoway-view/
TwoWayView Samples: https://github.com/lucasr/twoway-view/tree/master/sample
You can read a great tutorial about how to implement this on on this Github page.
You can take a look at VerticalHorizontalListView and twoway-view
and of course this link might be a help, which explains how to implement Dynamic Shelfview in Android.
I found this answer on SO :
Horizontal ScrollView in List View Item Android which explains the issue prefectly, you can take a look at that too. I hope this links help you ;)

Android ListView: Fixed number of rows for EVERY screen size

I have to create a listview inside a fragment that should always display the first 3 items no matter what screen size (rest should be scrollable). These 3 items should fill up the whole available space, which means that the item height has to be adjusted dynamically. You could also say: The first three items should take up about 33% of the listview each.
Is there a way achieving this using LinearLayout and layout weights? If not, what would be the best way to to this programatically, e.g. by determining current fragment size or something like that?
I managed to get the height and width using OnGlobalLayoutListener.
After all, we decided this wasn't a good idea layout-wise, but I thought someone might find this interesting nevertheless ;)
Try using the view.setMinimumHeight(int) on the inflated layout in your list adapter and supply it with a desired height.
As for obtaining screen size you can check this SO post
Edit: Apply that method to the layout that defines each item. You need a custom adapter and do that work in your getView method
You could probably calculate the size on the fly by determining the screen size, and adjusting the height of the list items as they are created & added to the list. This question and this one might help shed also shed some light on using weights, and would clean up your code.

Android resize entirely layout with all his views dynamically

I have added in a Relative Layout some ImageViews with some Buttons and gave them some width and high values.I have tested the application on a nexus 7 and everything looks great but when I tested on other devices some functions like a popUpWindow or even some Views look wrong.Is there a way how to resise a layout with all his views dynamically to fit every device I test on ?
The values you're using are probably not what you're looking for. Instead, you may mean to use wrap_content or match_parent.
Please have a look at this tutorial on layouts and absorb and practice some of that before immediately asking for help. You got this!

Scrolling a View by code

I want to programatically scroll a View. So far, I have found two possibilities :
scrollTo(x,y) : the top left hand corner of the View corresponds to the point (x,y) of what must be drawn in the View. The problem is that, after the call, it is impossible to manually scroll the View to have it displays what is above y or what is at the left of x.
setScrollY(y) : seems to be the function I'm looking for. But it is only available for API above level 14. And my application is supposed to work with API level 8.
Is there another function which could do what I want to do?
Thanks in advance for the time you will spend trying to help me.
Is your View in a ScrollView? If not, you will need to handle events yourself to manually scroll the View after you use code to set the scroll location. It sounds like you want both manual and programmatic control, so you'll need to use a scrolling container or handle touch events yourself.

Categories