0

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>
Mattia Maestrini
  • 32,270
  • 15
  • 87
  • 94
jere
  • 57
  • 9
  • Is there a reason why you're extending ScrollView? – Karim May 20 '15 at 09:17
  • Hi Karim, because all tutorial or example extending ScrollView, i created my personal ScrollView. – jere May 20 '15 at 09:21
  • The reason I asked is: if all you need is the (x,y) coordinates of the scrolling position, check this answer: http://stackoverflow.com/a/23365539/1065810 It's simple and short. – Karim May 20 '15 at 09:25
  • I seek to know the position of my top ScrollView I normally 0 When I'm high, but if I keep up movement to low position becomes negative ? – jere May 20 '15 at 09:35
  • Let me explain, I would close my fragment when you scroll above the maximum . ( movement from top to bottom when I max and I insist after 50 / 100px I close the activity ) . – jere May 20 '15 at 10:22
  • Sorry @jere, I still don't understand the issue. I hope someone else can help. – Karim May 20 '15 at 10:47
  • The idea is a remake SwipeRefreshLayout but to close the Fragment – jere May 20 '15 at 11:33

1 Answers1

0

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 .

https://i.stack.imgur.com/nPgrQ.png

or here : http://openclassrooms.com/forum/sujet/android-scrollview-detecter-le-top?page=1#message-88666797

jere
  • 57
  • 9