GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 横滑加载更多,修改后的横滑最后一页在滑动到最大后会有轻微的弹性效果, · tmexcept/AndroidCustomView@09c3a86

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • app/src/main
    • java/com/allen/androidcustomview/stretch
      • PicsViewPagerAdapter.java
      • StretchPager.java
      • StretchPagerTestActivity.java
    • res/layout
      • test_stretch_activity.xml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎app/src/main/java/com/allen/androidcustomview/stretch/PicsViewPagerAdapter.java‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/allen/androidcustomview/stretch/PicsViewPagerAdapter.java
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.widget.ImageView;
99

1010
import com.allen.androidcustomview.R;
11+
import com.allen.androidcustomview.utils.LogX;
1112

1213
import java.util.List;
1314

@@ -44,6 +45,7 @@ public void destroyItem(ViewGroup container, int position, Object object) {
4445

4546
@Override
4647
public Object instantiateItem(ViewGroup container, int position) {
48+
LogX.d("instantiateItem position="+position);
4749
View view = layoutInflater.inflate(R.layout.item_pic, container, false);
4850
ImageView iv_pic = view.findViewById(R.id.iv_pic);
4951
iv_pic.setImageResource(R.mipmap.beijing);
Collapse file

‎app/src/main/java/com/allen/androidcustomview/stretch/StretchPager.java‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/allen/androidcustomview/stretch/StretchPager.java
+5-41Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public class StretchPager extends ViewPager implements ValueAnimator.AnimatorUpd
4747
private boolean isAnimalRunning = false;
4848
/** 触摸在边界位置合法*/
4949
private boolean validTouch = false;
50-
private View leftView,rightView;
5150
private boolean isFirstMove,isMoveX;
5251

5352
public StretchPager(@NonNull Context context) {
@@ -61,8 +60,6 @@ public StretchPager(@NonNull Context context, @Nullable AttributeSet attrs) {
6160
}
6261
private int distanceMax;
6362
public void setRefreshView(View leftView,View rightView, int distanceMax){
64-
this.leftView = leftView;
65-
this.rightView = rightView;
6663
this.distanceMax = distanceMax;
6764
if(leftView != null){
6865
refreshModel |= STRETCH_LEFT;
@@ -100,19 +97,6 @@ public void setAnimDuration(int duration){
10097
this.anim.setDuration(duration);
10198
}
10299

103-
@Override
104-
protected void onLayout(boolean changed, int l, int t, int r, int b) {
105-
super.onLayout(changed, l, t, r, b);
106-
final int count = getChildCount();//重新放置位置
107-
View child = getChildAt(count-1);
108-
if(child != null && (leftView == child || rightView == child)) {
109-
int width = getMeasuredWidth();
110-
int left = expectDistance + (child == leftView ? -width : width);
111-
int right = left + width;
112-
child.layout(left, 0, right, getMeasuredHeight());
113-
}
114-
}
115-
116100
@Override
117101
public boolean dispatchTouchEvent(MotionEvent ev) {
118102
int actionId = ev.getAction() & MotionEvent.ACTION_MASK;
@@ -203,48 +187,27 @@ private boolean getStretchEnable(int distanceX){
203187
}
204188

205189
private void scrollByMove(int x){
206-
addLeftRightEdge();
207190
int total = 8*getWidth()/10;
208191
int scroll = getScrollX() - firstScrollX;
209192
double dx = Math.signum(-x) * (scroll>0.9*total ? (scroll>total ? 0 : 1) : 0.5*Math.abs(x));
210193
LogX.d("scrollByMove x="+x+" dx="+dx+" scroll="+scroll+" distanceMax="+distanceMax);
211194

212195
if(scroll < distanceMax) {
213196
scrollBy((int) dx, 0);
214-
if (null != listener) {
215-
listener.onScrolled(directionModel, getScrollDistance());
216-
}
217197
} else if(getAdapter().getCount() == getCurrentItem()+1) {
218198
if(x > 0) {
219199
scrollBy((int) dx, 0);
220-
if (null != listener) {
221-
listener.onScrolled(directionModel, getScrollDistance());
222-
}
223200
}
224201
} else if(0 == getCurrentItem()){
225202
if(x < 0) {
226203
scrollBy((int) dx, 0);
227-
if (null != listener) {
228-
listener.onScrolled(directionModel, getScrollDistance());
229-
}
230204
}
231205
}
232-
}
233-
234-
private void addLeftRightEdge(){
235-
if(directionModel == STRETCH_LEFT && leftView != null && leftView.getParent()==null){
236-
addEdgeView(leftView);
237-
}else if(directionModel == STRETCH_RIGHT && rightView != null && rightView.getParent()==null){
238-
addEdgeView(rightView);
206+
if (null != listener) {
207+
listener.onScrolled(directionModel, scroll);
239208
}
240209
}
241210

242-
private void addEdgeView(View view){
243-
LayoutParams p = new LayoutParams();
244-
p.isDecor = true;
245-
addView(view,p);
246-
}
247-
248211
private void scrollEndMove() {
249212
final int scrollDistance = getScrollDistance();
250213
if (null != listener) {
@@ -267,11 +230,12 @@ public void onAnimationUpdate(ValueAnimator animation) {
267230
int dx = (int) ((percent>1.0f ? 1.0:percent) * firstTotalDistance) - lastTotalDistance;
268231
lastTotalDistance += dx;
269232
scrollBy(dx, 0);
233+
if (null != listener) {
234+
listener.onScrolled(directionModel, getScrollX() - firstScrollX);
235+
}
270236
if(1.0f <= percent || distance == 0){
271237
anim.removeAllUpdateListeners();
272238
if(null != listener)listener.onRelease(directionModel);
273-
removeView(leftView);
274-
removeView(rightView);
275239
lastTotalDistance = 0;
276240
isAnimalRunning = false;
277241
stretchStatus = false;
Collapse file

‎app/src/main/java/com/allen/androidcustomview/stretch/StretchPagerTestActivity.java‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/allen/androidcustomview/stretch/StretchPagerTestActivity.java
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
import android.view.animation.Animation;
1111
import android.view.animation.RotateAnimation;
1212
import android.widget.ImageView;
13+
import android.widget.LinearLayout;
1314
import android.widget.TextView;
1415
import android.widget.Toast;
1516

1617
import com.allen.androidcustomview.R;
18+
import com.allen.androidcustomview.utils.LogX;
1719
import com.allen.androidcustomview.utils.ScreenTools;
1820

1921
import java.util.ArrayList;
@@ -26,6 +28,8 @@ public class StretchPagerTestActivity extends AppCompatActivity implements OnStr
2628
View leftView,rightView;
2729
private ConstraintSet constraintSet;
2830
private ConstraintLayout constraintLayout;
31+
private int screenW;
32+
private LinearLayout ll_right;
2933

3034
@Override
3135
protected void onCreate(Bundle savedInstanceState) {
@@ -35,6 +39,8 @@ protected void onCreate(Bundle savedInstanceState) {
3539
constraintLayout = findViewById(R.id.constraint);
3640
constraintSet = new ConstraintSet();
3741
constraintSet.clone(constraintLayout);
42+
screenW = ScreenTools.getScreenWidth();
43+
ll_right = findViewById(R.id.ll_right);
3844

3945
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
4046
@Override
@@ -110,6 +116,12 @@ public void onScrolled(int direction, int distance) {
110116
}
111117
}
112118
lastStatus = status;
119+
120+
// ll_right.setPadding(distance, 0, 0, 0);
121+
// ll_right.setPadding(screenW - distance, 0, 0, 0);
122+
constraintSet.connect(R.id.ll_right, ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START, screenW - distance);
123+
constraintSet.applyToWithoutCustom(constraintLayout);
124+
LogX.d("onScrolled "+distance);
113125
}
114126
}
115127

Collapse file

‎app/src/main/res/layout/test_stretch_activity.xml‎

Copy file name to clipboardExpand all lines: app/src/main/res/layout/test_stretch_activity.xml
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
<LinearLayout
1818
android:id="@+id/ll_right"
1919
android:orientation="horizontal"
20-
android:layout_width="62dip"
20+
android:layout_width="match_parent"
2121
android:layout_height="match_parent"
22-
app:layout_constraintStart_toStartOf="parent"
23-
android:layout_marginStart="100dip">
22+
app:layout_constraintStart_toStartOf="parent" >
2423

2524
<ImageView android:id="@+id/iv_pull"
2625
android:layout_width="12dip"

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.