Putting a View on top of Scroll View while Scrolling down - android

Basically, I have a Scroll View and it contains several child inside Linear Layout. Now, I want to show a View constantly on the top of the screen when it is scrolled down.If it is scrolled up everything should be as it was earlier.
Can anyone just help me out? Any help would be appreciated! (Thanks in advance).

Define a ObservableScrollView class entends ScrollView.
Then write your layout xml like this:
<RelativeLayout>
<View/>
<ObservableScrollView>
</ObservableScrollView>
<RelativeLayout>
In ObservableScrollView class,focus on this onScrollChanged function.
Change the visibility of your target view by param 'y'.

Related

Center RecycleView in Parent - Android

I am following a tutorial on grid layout. In particular, I am replicating Suragch's answer.
The code itself is working fine, except I would like to center the RecyclerView in the activity.
I've tried
android:gravity="center"
and
android:layout_gravity="center"
on both the RelativeLayout AND RecyclerView, but neither works.
Also, I would like to eliminate the gaps between each column. Does anyone know how to go about doing this?
Try android:layout_centerInParent=true into <RecyclerView>
Depending on your parent Layout
If its RelativeLayout then
android:layout_centerHorizontal=true in RecyclerView
if its LinearLayout then
android:layout_gravity=center_horizontal in RecyclerView
One more interesting thing you can do in Adapter
the main parent Layout in adapter
try doing this
android:gravity=center_horizontal in main layout of adapter

Showing full height layout above recyclerview inside scrollview

As the title says. I'm trying to display extremely complex layout with a full height of the viewport but I need it scrollable because under it there is a simple recyclerview with some items. I already thought about putting everything inside a multi type recyclerview adapter but the logic of the upper layout is so complex that I don't think it's possible.
I tried using NestedScrollView with fillViewport set to true but I'm stuck defining dimensions of this upper layout and recyclerview below it. Everything needs to be inside one layout because scrollview can't have more than one child, but when I put everything in a linearlayout and set the upper layout to match_parent it's showing fullscreen until data loads in the recyclerview below it. Then it's treating this upper layout as if it was wrap_content.
I'm out of ideas how can I do something like this. Preferably best would be to have some sort of ViewGroup which would support scrolling and resize the recyclerview below it as we scroll, but I'm not sure how to do it.
you need to set the layout to something like this:
<NestedScrollView - height:match_parent>
<LinearLayout - height:wrap_content>
<LinearLayout(topview) - height:wrap_content/>
<RecyclerView - height:wrap_content />
</LinearLayout>
</NestedScrollView>
And then you programmatically change the height of the "topview" to equal nestedscrollview.

Listview scroll with other elements on page

In my layout, I have two items; an ImageView and a ListView, the ImageView appears on top of the ListView in a LinearLayout. The ImageView displays a logo or a profile image while the ListView displays a list of personal / company info.
Now this is my problem, the ListView scrolls on it's own with the ImageView fixed at the top but I want the ImageView to scroll with the ListView so that it is not fixed statically on top.
How do I do this? Is this possible? And if yes can I see an example. Thanks. :)
Edit: I have considered removing the scroll from the ListView and simply just displaying the items without scroll then I can wrap both the ImageView and ListView inside a ScrollView. However I do not know if this is possible or how I can implement it.
Take NestedScrollView as you parent layout and add a LinearLayout as it's child and add your ImageView and listView as child to this linear layout .
<NestedScrollView>
<LinearLayout>
<ImageView/>
<ListView/>
</LinearLayout>
</NestedScrollView>

Get notified when the user is viewing a certain item in a scroll view and scroll to desired view

I have a (vertical) linear layout inside a scroll view. The linear layout houses a set of other layouts.
<ScrollView>
<LinearLayout>
<layout1></layout1>
<layout2></layout2>
<layout3></layout3>
<layout4></layout4>
<LinearLayout>
</ScrollView>
I would like to be notified when a certain child of the linear layout is in view and be able to scroll to a desired layout.
Is there any way to achieve that?

How to make Verital and Horizontal scroll on 2 layouts?

I am trying to make Layout that contains 2 layout, vertical and horizontal scrolls.
Like this :
http://202.131.244.11/demo/VerticalAndHorizontalScrolls.PNG
How to make it ?
I've tried it. But horizontal scroll doesn't work for me.
Please advise.
What's your layout xml look like? Presumably, you want a hierarchy like this:
ScrollView
ViewGroup (some sort of layout to contain everything)
ViewGroup (layout 1)
HorizontalScrollView
ViewGroup (layout 2)

Categories

Resources