For my app I want to enable a thing looking somehow like this:
<ScrollView>
<LinearLayout orientation="vertical">
<FrameLayout layout_height="48dp">
Anything I want here...
</FrameLayout>
<ListView>
It's size will be set to screen height anyway
</ListView>
</LinearLayout>
</ScrollView>
And I want to do so, that when user touches the screen to scroll, at first only scrollview scrolls, and then, when it reaches one of its edges the scroll event goes to listview and it begans scrolling.
How can I achieve that?
P.S. the reason for this is to make some kind of hiding actionbar, which scrolls off the screen when user goes deeper down, and then as he scrolls up it should appear from bottom not with an animation but as the list is moved. so if i scrolled the list half the height of the actionbar - i see the bottom half of the actionbar on the screen.
You can see what I mean in iOS Google+ app.
Any help will be appreciated.
in Layaout set Parameter
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</ScrollView>
And in the Coding Part Set the Dynamic height of listview according to device height
LayoutParams lp = (LayoutParams) list1.getLayoutParams();
int height = (arraylist.size()) * 80;
//arraylist list is in which all data is kept
lp.height = height;
listview.setLayoutParams(lp);
listview.setAdapter(Adapter);
* ListView lv = (ListView)findViewById(R.id.myListView);
lv.setOnTouchListener(new ListView.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
v.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
// Handle ListView touch events.
v.onTouchEvent(event);
return true;
}
});k;
}
// Handle ListView touch events.
v.onTouchEvent(event);
return true;
}
});*
setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
mFirstVisibleItem = firstVisibleItem;
mLastVisibleItem = firstVisibleItem + visibleItemCount;
mTotalOfItems = totalItemCount;
}
});
I did it to know where I'm scrolling, using OnScrollListener and OnTouchListener to know to where I'll scroll, it works fine for me...
setOnTouchListener(new OnTouchListener() {
float oldY = -1;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
oldY = event.getY();
v.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
if (oldY > -1 &&
(mFirstVisibleItem == 0 && oldY < event.getY()) ||
(mLastVisibleItem >= mTotalOfItems && oldY > event.getY())) {
v.getParent().requestDisallowInterceptTouchEvent(false);
}
v.onTouchEvent(event);
return true;
}
});