ScrollViewExt - onScrollChanged don't work - android

I've a little problem on my ScrollViewExt. When I scroll in my view no log is displayed. I read similar problems but I wonder if the use of fragment doesn't change the code a bit ?
In my Log I've just :
ScrollViewExt﹕ setOnScrollViewListener
Thx all for your answers.
ScrollViewExt :
public class ScrollViewExt extends ScrollView {
private OnScrollViewListener scrlViewListener;
public ScrollViewExt(Context context) {
super(context);
}
public ScrollViewExt(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollViewExt(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public void setOnScrollViewListener(OnScrollViewListener l) {
Log.d("ScrollViewExt", "setOnScrollViewListener ");
this.scrlViewListener = l;
}
#Override
protected void onScrollChanged(int x, int y, int oldx, int oldy) {
Log.d("ScrollViewExt", "onScrollChanged");
super.onScrollChanged(x, y, oldx, oldy);
if(scrlViewListener != null) {
scrlViewListener.onScrollChanged(this, x, y, oldx, oldy);
}
}
}
FragmentNew.java :
public class FragmentNew extends Fragment implements OnScrollViewListener {
ScrollViewExt scrlvNew;
public FragmentNew() {
}
#Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_new, container,
false);
scrlvNew = (ScrollViewExt) view.findViewById(R.id.scrlvFragmentNew);
scrlvNew.setOnScrollViewListener(this);
return view;
}
#Override
public void onScrollChanged(ScrollViewExt v, int x, int y, int oldl, int oldt) {
Log.d("FragmentNew", "onScrollChanged");
Log.d("Fragment", "x : " + x);
Log.d("Fragment", "y : " + y);
Log.d("Fragment", "oldx : " + oldl);
Log.d("Fragment", "oldy : " + oldt);
}
}
My Layout :
<?xml version="1.0" encoding="utf-8"?>
<com.application.view.ScrollViewExt
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrlvFragmentNew"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical"
android:overScrollMode="always"
android:isScrollContainer="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="outsideInset"
android:scrollbars="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#android:color/black"/>
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:textColor="#android:color/black"
android:layout_below="#+id/title"/>
</RelativeLayout>
</com.application.view.ScrollViewExt>

I managed to get a result but I completely change the layout for a SwipeRefreshLayout .
What I hope to achieve is in this idea, but the only thing he really misses me and if that is not possible it is shameful :-) , change the arrow that turns, and I want to put a cross . I managed to hide the arrow but not with a cross .
http://i.stack.imgur.com/nPgrQ.png
or here :
http://openclassrooms.com/forum/sujet/android-scrollview-detecter-le-top?page=1#message-88666797

Related

HorizontalScrollView in RecycleView scrollRight at the beginning

I'm trying to use HorizontalScrollView in recycle view, so each item will have all his data inside, and i'm trying to start it all the way right. but not matter what i'm trying, i still see the left side of scroll view for few milliseconds before it scroll itself to end
my layout:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.cobox.core.ui.views.CustomHorizontalScollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/horizontal_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:id="#+id/view_home_card_and_button_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="150dp"
android:background="#color/amber_200" />
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/half_unit"
app:cardCornerRadius="4dp">
</android.support.v7.widget.CardView>
</LinearLayout>
</com.cobox.core.ui.views.CustomHorizontalScollView>
The scrollView:
public class CustomHorizontalScollView extends HorizontalScrollView {
public OnScrollChangedListener mOnScrollChangedListener;
public CustomHorizontalScollView(Context context) {
super(context);
}
public CustomHorizontalScollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomHorizontalScollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (mOnScrollChangedListener != null) {
mOnScrollChangedListener.onScrollChanged(l, t, oldl, oldt);
}
}
public void setOnScrollChangedListener(OnScrollChangedListener onScrollChangedListener) {
this.mOnScrollChangedListener = onScrollChangedListener;
}
public interface OnScrollChangedListener {
void onScrollChanged(int l, int t, int oldl, int oldt);
}
}
and the relevant part on code:
public class HomeScreenCardView extends FrameLayout implements
HomeCardActionsListener {
public HomeScreenCardView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.context = context;
init(attrs, defStyle);
}
...
private void init(AttributeSet attrs, int defStyle) {
WindowManager wm = ((Activity) context).getWindowManager();
Display d = wm.getDefaultDisplay();
ViewGroup.LayoutParams layoutParams2 = mCardView.getLayoutParams();
float dip = 8f;
float px = getPxFromDp(dip);
layoutParams2.width = (int) (d.getWidth() - px * 2);
mCardView.setLayoutParams(layoutParams2);
horizontalScrollView.post(new Runnable() {
#Override
public void run() {
horizontalScrollView.setSmoothScrollingEnabled(false);
horizontalScrollView.fullScroll(View.FOCUS_RIGHT);
horizontalScrollView.setSmoothScrollingEnabled(true);
}
});
}
try
In your java code
horizontalScrollView.setLayoutDirection(View.FOCUS_RIGHT);
and in XML
android:layoutDirection="rtl"
Replace your code of scrolling with code below
ViewTreeObserver vto = horizontalScrollView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){
#Override
public void onGlobalLayout() {
horizontalScrollView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
horizontalScrollView.setSmoothScrollingEnabled(false);
horizontalScrollView.scrollTo(horizontalScrollView.getWidth(), 0);
horizontalScrollView.setSmoothScrollingEnabled(false);
}
});

notifyDataSetChanged() refresh the whole layout

I didn't describe the question in a good way, so I edit the question to be clear.
I am so confused about this: I wrote a RelativeLayout with a DragViewGroup and a gridview, and I noticed that every time when I used notifyDatasetChanged() method would cause the DragViewGroup do the redrawing thing.And the DragViewGroup extends from LinearLayout which uses ViewDragHelper, so I could not maintain the position already scrolled to.
Here is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.xxxx.DragViewGroup
android:id="#+id/dragview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#3f83f7"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="665dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="310dp"
android:id="#+id/mainview"
>
...
</RelativeLayout>
<include
android:layout_width="match_parent"
android:layout_height="355dp"
android:layout_marginBottom="62dp"
layout="#layout/fake_panel" />
</LinearLayout>
</com.xxxx.DragViewGroup>
<RelativeLayout
android:layout_width="match_parent"
android:id="#+id/layout"
android:layout_alignParentBottom="true"
android:layout_height="210dp"
android:background="#ffffff"
android:clickable="true"
>
<HorizontalScrollView
android:id="#+id/btn_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"
android:layout_alignParentBottom="true"
android:layout_marginBottom="26dp"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:listSelector="#color/transparent"
android:horizontalSpacing="6dp"
android:scrollbars="none" />
</LinearLayout>
</HorizontalScrollView>
<com.xxxx.UniversalSeekBar
....
android:layout_marginTop="18dp"/>
</RelativeLayout>
</RelativeLayout>
DragViewGroup code:
public class DragViewGroup extends LinearLayout {
private ViewDragHelper viewDragHelper;
private View mainView;
private int mainHeight;
public DragViewGroup(Context context) {
super(context);
initView();
}
public DragViewGroup(Context context, AttributeSet attrs) {
super(context, attrs);
initView();
}
public DragViewGroup(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView();
}
#Override
protected void onFinishInflate() {
super.onFinishInflate();
mainView = getChildAt(0);
}
#Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mainHeight = mainView.findViewById(R.id.mainview).getMeasuredHeight();
}
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return viewDragHelper.shouldInterceptTouchEvent(ev);
}
#Override
public boolean onTouchEvent(MotionEvent event) {
viewDragHelper.processTouchEvent(event);
return true;
}
#Override
public void computeScroll() {
if (viewDragHelper.continueSettling(true)) {
ViewCompat.postInvalidateOnAnimation(this);
}
}
private void initView() {
viewDragHelper = ViewDragHelper.create(this, callback);
}
private ViewDragHelper.Callback callback = new ViewDragHelper.Callback() {
#Override
public boolean tryCaptureView(View child, int pointerId) {
return mainView == child;
}
#Override
public int clampViewPositionHorizontal(View child, int left, int dx) {
return 0;
}
#Override
public int clampViewPositionVertical(View child, int top, int dy) {
return top;
}
#Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
super.onViewReleased(releasedChild, xvel, yvel);
if (mainView.getTop() > -500) {
viewDragHelper.smoothSlideViewTo(mainView, 0, 0);
ViewCompat.postInvalidateOnAnimation(DragViewGroup.this);
} else {
viewDragHelper.smoothSlideViewTo(mainView, 0, -mainHeight);
ViewCompat.postInvalidateOnAnimation(DragViewGroup.this);
}
}
};
}
Once I use the notifyDatasetChanged() method to update the gridview, my DragViewGroup will slide to the original position itself although it has been dragged before. Apparently the method draw the whole layout instead of only drawing gridview itself.
I need to maintain the dragged position of DragViewGroup, I have tried that override onDraw method in DragViewGroup like this:
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// set isDragged label in onViewReleased()
if (isDragged) {
viewDragHelper.smoothSlideViewTo(main, 0, -mainHeight);
}
}
It works, but there is a visible sliding process which I don't want.
Hope someone could help me.Thanks very much.
Store ScrollValue at the time of the scrolling the view, and just use setSelectionMethod on your gridview
gridview.setOnScrollListener(new OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
int count = gridview.getCount();
if (scrollState == SCROLL_STATE_IDLE) {
if (gridview.getLastVisiblePosition() >= count
- 1) {
scrollPos = <positionOfList>;
}
}
}
});
Here enter your last position insted of "positionOfList"
And just after calling notifydatasetChanged() call gridview.setSelection(scrollPos)
Hope this will help you!
Just use bellow code in class that you update display:
int index = myList.getFirstVisiblePosition();
View v = myList.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();
myList.setAdapter(adapter);
adapter.notifyDataSetChanged();
myList.setSelectionFromTop(index, top);

Vertical Parallax scrolling in android

I want to achieve parallax scrolling in android without using external library.Is there anyway to achieve this same as in google play store.
Thanks
To implement that in a RecyclerView:
public class MyScrollListener extends RecyclerView.OnScrollListener {
private int totalScrollDistance = 0;
private View parallax;
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
totalScrollDistance += dy;
if (parallax == null) {
parallax = recyclerView.getChildAt(0);
}
parallax.setTranslationY(totalScrollDistance/2);
}
}
Setup:
mRecyclerView.setOnScrollListener(new MyScrollListener());
To implement that in a ScrollView, you have to implement a OnScrollListener:
public class MyScrollView extends ScrollView {
private int lastScrollY;
private OnScrollListener listener;
public void setOnScrollListener(OnScrollListener listener) {
this.listener = listener;
}
private Handler handler = new Handler() {
#Override
public void handleMessage(Message msg) {
int scrollY = getScrollY();
if (lastScrollY != scrollY) {
lastScrollY = scrollY;
// update when lastScrollY != scrollY and keep sending message till lastScrollY == scrollY
handler.sendMessageDelayed(handler.obtainMessage(), 5);
}
if (listener != null) {
listener.onScroll(scrollY);
}
}
};
public MyScrollView(Context context) {
super(context);
}
public MyScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public MyScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
#Override
public boolean onTouchEvent(MotionEvent ev) {
lastScrollY = getScrollY();
if (listener != null) {
listener.onScroll(lastScrollY);
}
if (ev.getAction() == MotionEvent.ACTION_UP) {
//might still scrolling after touching, use a handler to handle it
handler.sendMessageDelayed(handler.obtainMessage(), 5);
}
return super.onTouchEvent(ev);
}
public interface OnScrollListener {
void onScroll(int dy);
}
}
Then do what we did in OnScrollListener of RecyclerView:
scrollView = (MyScrollView) findViewById(R.id.my_scrollview);
final View parallax = ((ViewGoup) scrollView.getChildAt(0)).getChildAt(0);
scrollView.setOnScrollListener(new MyScrollView.OnScrollListener() {
#Override
public void onScroll(int dy) {
parallax.setTranslationY(dy/2);
}
});
For me the following method worked out .
In your android layout mention the below code:`
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:background="#color/white"
>
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
//place the widgets that you want to collapse .....(here i have used an
ImageView)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/imgViewFirst"
android:src="#drawable/firstImage"
android:scaleType="fitXY"/>
</LinearLayout>
</android.support.design.widget.CollapsingToolbarLayout>
//place the widgets that you want to pin after scrolling up.....
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/lightGrey"/>
</android.support.design.widget.AppBarLayout>
//place the widgets you want to show after you scrolled upwards...(here i have
used an ImageView)
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/imgViewSecond"
android:src="#drawable/secondImage"
android:scaleType="fitXY"/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>`

How do I resize my imageview within my scrollview as it is done in this image?

I have created a scrollview and an imageview is placed within it. I'd like on scroll for it to resize in the same fashion it is done in the image below but so far I've had little success.
In my attempts the image is resized on scroll but, there is space left over after the resize. How would you modify the below:
Image:
My Code so far:
activity_main.xml
<ImageView
android:layout_gravity="center"
android:adjustViewBounds="true"
android:layout_width="601dp"
android:layout_height="250dp"
android:paddingTop="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:scaleType="fitXY"
android:id="#+id/contactPic"
android:src="#drawable/stock"
android:clickable="true"/>
MainActivity:
#Override
public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {
final ImageView contactPicture = (ImageView) findViewById(R.id.contactPic);
final RelativeLayout contactLayout = (RelativeLayout) findViewById(R.id.ContactRLayout);
if (scrollView == contactScrollView) {
View view = (View) scrollView.getChildAt(scrollView.getChildCount() - 1);
int distanceFromPageEnd = (view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()));
Log.e("onScrollChanged", "distance from bottom = " + String.valueOf(distanceFromPageEnd));
if (distanceFromPageEnd >= 1408)
{
contactPicture.getLayoutParams().height = (distanceFromPageEnd - 1408);
contactPicture.requestLayout();
}
}
ScrollViewListener:
public interface ScrollViewListener {
void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy);
}
ObservableScrollView:
public class ObservableScrollView extends ScrollView {
private ScrollViewListener scrollViewListener = null;
public ObservableScrollView(Context context) {
super(context);
}
public ObservableScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public ObservableScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setScrollViewListener(ScrollViewListener scrollViewListener) {
this.scrollViewListener = scrollViewListener;
}
public void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
}
#Override
protected void onScrollChanged(int x, int y, int oldx, int oldy) {
super.onScrollChanged(x, y, oldx, oldy);
if(scrollViewListener != null) {
scrollViewListener.onScrollChanged(this, x, y, oldx, oldy);
}
}
}
There is simple example below that shows how to achieve parallax effect.
First, put your ImageView and other views into FrameLayout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/flWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/contactPic"
android:layout_width="match_parent"
android:layout_height="#dimen/contact_photo_height"
android:scaleType="centerCrop"
android:src="#drawable/stock" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/contact_photo_height">
<!-- Other Views -->
</LinearLayout>
</FrameLayout>
</ScrollView>
LinearLayout's top margin is equal to the ImageViews's height (#dimen/contact_photo_height in our example).
Then we should listen scroll position of the ScrollView and change the position of ImageView:
#Override
protected void onCreate(Bundle savedInstanceState) {
<...>
mScrollView = (ScrollView) findViewById(R.id.scrollView);
mPhotoIV = (ImageView) findViewById(R.id.contactPic);
mWrapperFL = (FrameLayout) findViewById(R.id.flWrapper);
mScrollView.getViewTreeObserver().addOnScrollChangedListener(new ScrollPositionObserver());
<...>
}
private class ScrollPositionObserver implements ViewTreeObserver.OnScrollChangedListener {
private int mImageViewHeight;
public ScrollPositionObserver() {
mImageViewHeight = getResources().getDimensionPixelSize(R.dimen.contact_photo_height);
}
#Override
public void onScrollChanged() {
int scrollY = Math.min(Math.max(mScrollView.getScrollY(), 0), mImageViewHeight);
// changing position of ImageView
mPhotoIV.setTranslationY(scrollY / 2);
// alpha you could set to ActionBar background
float alpha = scrollY / (float) mImageViewHeight;
}
}

How to set images for ScrollView instead-of fading edges?

I am using Horizontal Scroll View, dynamically i will add items in to that. if no. of items are more than displaying items on the screen i want to show image(arrow) at the edges ( like scroll view shows fading edges). How can i do it.
just look at below image, i want create like that.
this is the xml code
<HorizontalScrollView
android:layout_width="wrap_content"
android:scrollbars="none"
android:id="#+id/app_category"
android:layout_below="#+id/top_layout"
android:background="#drawable/minitopbar"
android:layout_height="30dp">
<LinearLayout
android:orientation="horizontal"
android:id="#+id/app_category_scroll_layout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"/>
</HorizontalScrollView>
A. You have to create your own class, that extends HorizontalScrollView:
public class ExtendedHorizontalScrollView extends HorizontalScrollView {
private IScrollStateListener scrollStateListener;
public HorizontalScrollViewForMenu(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public HorizontalScrollViewForMenu(Context context, AttributeSet attrs) {
super(context, attrs);
}
public HorizontalScrollViewForMenu(Context context) {
super(context);
}
#Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
prepare();
}
private void prepare() {
if (scrollStateListener != null) {
View content = this.getChildAt(0);
if (content.getLeft() >= 0)
scrollStateListener.onScrollMostLeft();
if (content.getLeft() < 0)
scrollStateListener.onScrollFromMostLeft();
if (content.getRight() <= getWidth())
scrollStateListener.onScrollMostRight();
if (content.getLeft() > getWidth())
scrollStateListener.onScrollFromMostRight();
}
}
#Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (scrollStateListener != null) {
if (l == 0)
scrollStateListener.onScrollMostLeft();
else if (oldl == 0)
scrollStateListener.onScrollFromMostLeft();
int mostRightL = this.getChildAt(0).getWidth() - getWidth();
if (l >= mostRightL)
scrollStateListener.onScrollMostRight();
if (oldl >= mostRightL && l < mostRightL)
scrollStateListener.onScrollFromMostRight();
}
}
public void setScrollStateListener(IScrollStateListener listener) {
scrollStateListener = listener;
}
public interface IScrollStateListener {
void onScrollMostLeft();
void onScrollFromMostLeft();
void onScrollMostRight();
void onScrollFromMostRight();
}
}
B. Use it defining of layout:
<LinearLayout
.....>
<ImageView
android:id="#+id/navigation_left"
..... />
<your.custom.view.package.ExtendedHorizontalScrollView
android:id="#+id/scroller"
android:layout_width="0px"
android:layout_weight="1"
android:fadingEdge="none"
....>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</your.custom.view.package.ExtendedHorizontalScrollView>
<ImageView
android:id="#+id/navigation_right"
..... />
</LinearLayout>
C. Add logic for disabling arrows when you can't scroll any more.
((ExtendedHorizontalScrollView)findViewById(R.id.scroller)).setScrollStateListener(new IScrollStateListener() {
public void onScrollMostRight() {
((View) scroller.getParent()).findViewById(R.id.navigation_right).setVisibility(View.INVISIBLE);
}
public void onScrollMostLeft() {
((View) scroller.getParent()).findViewById(R.id.navigation_left).setVisibility(View.INVISIBLE);
}
public void onScrollFromMostLeft() {
((View) scroller.getParent()).findViewById(R.id.navigation_left).setVisibility(View.VISIBLE);
}
public void onScrollFromMostRight() {
((View) scroller.getParent()).findViewById(R.id.navigation_right).setVisibility(View.VISIBLE);
}
});
An easy alternative is to make a scrollview without fading edges and then add the image with arrow below or on top of the scrollview.
Your xml something similar:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:fadingEdge="none"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View
android:layout_height="6dp"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:background="#drawable/background_effect"/>
</RelativeLayout>
</FrameLayout>

Categories

Resources