|
4 | 4 | import android.content.res.Resources; |
5 | 5 | import android.graphics.drawable.ColorDrawable; |
6 | 6 | import android.support.v4.content.res.ResourcesCompat; |
| 7 | +import android.support.v4.widget.NestedScrollView; |
7 | 8 | import android.support.v7.widget.DividerItemDecoration; |
8 | 9 | import android.support.v7.widget.LinearLayoutManager; |
9 | 10 | import android.support.v7.widget.RecyclerView; |
10 | 11 | import android.util.AttributeSet; |
11 | 12 | import android.view.LayoutInflater; |
12 | 13 | import android.view.View; |
13 | 14 | import android.view.ViewGroup; |
| 15 | +import android.view.ViewTreeObserver; |
14 | 16 | import android.widget.FrameLayout; |
15 | 17 | import android.widget.ImageView; |
16 | 18 | import android.widget.TextView; |
@@ -40,6 +42,7 @@ class PaymentMethodView extends FrameLayout { |
40 | 42 |
|
41 | 43 | private Checkout checkout; |
42 | 44 | private List<PaymentMethod> availablePaymentMethods; |
| 45 | + private RecyclerView recyclerView; |
43 | 46 |
|
44 | 47 | public PaymentMethodView(Context context) { |
45 | 48 | super(context); |
@@ -74,16 +77,34 @@ private void inflateView() { |
74 | 77 | } |
75 | 78 | } |
76 | 79 |
|
77 | | - RecyclerView recyclerView = findViewById(R.id.payment_methods); |
| 80 | + recyclerView = findViewById(R.id.payment_methods); |
78 | 81 | recyclerView.setAdapter(new Adapter()); |
79 | 82 |
|
80 | | - LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); |
81 | | - layoutManager.setStackFromEnd(true); |
82 | | - layoutManager.scrollToPosition(0); |
| 83 | + LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()) { |
| 84 | + @Override |
| 85 | + public boolean canScrollVertically() { |
| 86 | + return false; |
| 87 | + } |
| 88 | + }; |
| 89 | + |
| 90 | + final NestedScrollView scrollView = findViewById(R.id.scroller); |
83 | 91 |
|
84 | 92 | recyclerView.setLayoutManager(layoutManager); |
85 | 93 | recyclerView.setItemAnimator(null); |
86 | 94 |
|
| 95 | + scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { |
| 96 | + @Override |
| 97 | + public void onGlobalLayout() { |
| 98 | + scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this); |
| 99 | + |
| 100 | + scrollView.post(new Runnable() { |
| 101 | + public void run() { |
| 102 | + scrollView.fullScroll(View.FOCUS_DOWN); |
| 103 | + } |
| 104 | + }); |
| 105 | + } |
| 106 | + }); |
| 107 | + |
87 | 108 | DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL); |
88 | 109 | int dividerColor = ResourcesCompat.getColor(getResources(), R.color.snabble_dividerColor, null); |
89 | 110 | dividerItemDecoration.setDrawable(new ColorDrawable(dividerColor)); |
|
0 commit comments