I am using WearableRecyclerView to create a curved layout,but the default scrollbar is still vertical.Is there a way to create a curved scrollbar like android wear 2.0 launcher?
Actually, the scrollbars are circular for any scrollable View that takes up the whole screen. It's a framework feature for Wear 2.0.
If the scrollbars are still vertical, make sure your View really does fill up the whole screen - set it to match_parent and as a top level root View.
use boxinsetlayout
//
android.support.wearable.view.BoxInsetLayout
app:layout_box="left|bottom|right"
...Your list View and other contents
android.support.wearable.view.BoxInsetLayout>
and if you are using wearableRecyclerView
do CircularChildLayoutManager mChildLayoutManager = new CircularChildLayoutManager(mContext);
and set this as layout manager for your recycler view.
mRecyclerView.setLayoutManager(mChildLayoutManager);
This may solve for you.
The API was renamed to CurvedChildLayoutManager
So use
val layoutManager = CurvedChildLayoutManager(this)
recyclerView.layoutManager = layoutManager
PS: as for topic question, you dont need app:layout_box just use android:scrollbars="vertical" on your WearableRecyclerView
https://developer.android.com/reference/android/support/wearable/view/CurvedChildLayoutManager.html
Related
I have a RecyclervView with a rounded Drawable background and .clipToOutline = true in order to keep the overscroll animation inside the background. When I set requiresFadingEdge="vertical", there's a glitch where the fading edge is; example below. How can I fix this? The issue doesn't appear when I set .clipToOutline = false or when I don't have a fading edge, but I would like both of these effects. Thanks for the help.
You can see the issue in the bottom corners of the blue RecyclerView.
This can be fixed by setting a different layer type either in xml, or programatically when initialising your recyclerview:
XML
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layerType="hardware"
...
Programatically
recyclerView.setLayerType(VIEW.LAYER_TYPE_HARDWARE, null)
You can also use LAYER_TYPE_SOFTWARE, but it's better to use LAYER_TYPE_HARDWARE for performance reasons.
Find out more about this 2 options in these docs:
https://developer.android.com/reference/android/view/View#LAYER_TYPE_HARDWARE
https://developer.android.com/reference/android/view/View#LAYER_TYPE_SOFTWARE
I have a layout containing an empty LinearLayout. I fill the LinearLayout with child views dynamically at runtime. Is there any way in which I could preview the layout in Android studio as if those child views were already in the layout XML?
Basically as you can use tools namespace to show a differen preview (tools:text="blabla") I would need something where the entire view would be under "tools" namespace so it would not be inside the app.
The idea I got was to add a view in XML, make it android:visibility="gone" and tools:visibility="visible" but I'm not sure is this a good approach? I wouldn't want to suddenly have double the rendering inside the app when it runs.
I am trying to share react native components between two screens, like what you can do with the hero library in ios. I want the component to animate between the two screens.
I have tried the fluid-transitions library, but I couldnt get it to work.
ie.
In order to do an animation like this you can use TransitionManager, i personally usually use it with constraintLayouts.
What you need in order to do this is 2 constraintLayouts (both need to have all the elements that will appear on screen and the properties that change between layouts should only be the constraints themselves.)
With the 2 layouts you can make an animation from one to the other like this:
final ConstraintSet constraint1 = new ConstraintSet();
constraint1.clone(getApplicationContext(), R.layout.layout_shrunk);
final ConstraintSet constraint2 = new ConstraintSet();
constraint2.clone(getApplicationContext(), R.layout.layout_expanded);
//The view you pass as an argument to both methods should be the layout's root.
TransitionManager.beginDelayedTransition((ConstraintLayout)findViewById(R.id.layout_root));
constraint2.applyTo((ConstraintLayout) findViewById(R.id.layout_root));
Result:
However this kind of animations are also possible to be made in other ways, please check the official docs for reference: https://developer.android.com/training/transitions
Note: to get the reverse animation too just apply the other constraintSet.
Looking for a horizontal list view GUI componnet in Android similar to UICollectionView in iOS. I trid ListView but was not able to set up to scroll it horizontally.
I need only one line, so no grid like multi line 'table'. I know about TableLayout and GridLayout. Which one is more proper for my purpose?
Looking for not a 3rd party solution but a standard Android one without loading in and library.
You should be using the RecyclerLayout, which allows you to specify your own LayoutManager (then you can specify a horizontal one, or a vertical one, or a grid one, or...)
Here is a good SO with a simple example: How to build a Horizontal ListView with RecyclerView?
You can use RecycleView and add horizontal layoutmanager
RecyclerView listView= (RecyclerView)findViewById(R.id.hlistview);
LinearLayoutManager layoutManager=new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);
listView.setLayoutManager(layoutManager);
and in xml
<android.support.v7.widget.RecyclerView
android:id="#+id/hlistview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="30dp"/>
I'm implementing an Android TV app and I'm using HorizontalGridView from the Leanback library. I have a custom layout.
I have to scroll the HorizontalGridView to specific position, after activity is created, but unfortunately the scrollToPositio(position) method is not working on this layout at all. It just do nothing. I found, that when I specifically set the layout manager to LinearLayoutManager it works. But the problem is, that when I'm not using leanback default HorizontalGridView LayoutManager, there is a problem with focusing next items using D-pad.
Basically if I use normal RecyclerView, the control with D-pad is not working as expected, so I decided to go with leanback implementation, where this problem is solved, but so far I cannot make it work with scrollToPosition method.
Any ideas?
Snippet of my code:
Layout:
<android.support.v17.leanback.widget.HorizontalGridView
android:id="#+id/photo_gallery_recycler"
android:layout_width="match_parent"
android:layout_height="#dimen/gallery_image_size"
android:clipChildren="false"
app:itemView="#{viewModel.photoItemView}"
app:items="#{viewModel.photosUrl}"/>
Code [Kotlin]:
binding.photoGalleryRecycler.scrollToPosition(position)
binding.photoGalleryRecycler.getChildAt(position)?.requestFocus()
And I also tried some hacks like this:
// save default leanback layout manager
var defaultLayoutManager = binding.photoGalleryRecycler.layoutManager
// set LinearLayoutManager
binding.photoGalleryRecycler.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false)
// scroll to position and request focus
binding.photoGalleryRecycler.scrollToPosition(position)
binding.photoGalleryRecycler.getChildAt(position)?.requestFocus()
// set default layout manager back to the view
binding.photoGalleryRecycler.layoutManager = defaultLayoutManager
you need to be using setSelectedPosition(position)
If animation is required you can try setSelectedPositionSmooth(position)
setSelectedPosition Developer docs.