use of android.support.v4.widget.NestedScrollView in project RxBinding by JakeWharton.
the class RxNestedScrollViewTestActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScrollView scrollView = new ScrollView(this);
nestedScrollView = new NestedScrollView(this);
emptyView = new FrameLayout(this);
LayoutParams scrollParams = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
LayoutParams emptyParams = new LayoutParams(50000, 50000);
nestedScrollView.addView(emptyView, emptyParams);
scrollView.addView(nestedScrollView, scrollParams);
setContentView(scrollView, scrollParams);
}
use of android.support.v4.widget.NestedScrollView in project GSYVideoPlayer by CarGuo.
the class WebDetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_detail);
ButterKnife.bind(this);
String url = "http://baobab.wdjcdn.com/14564977406580.mp4";
//String url = "https://d131x7vzzf85jg.cloudfront.net/upload/documents/paper/b2/61/00/00/20160420_115018_b544.mp4";
webPlayer.setUp(url, true, null, "测试视频");
//增加封面
ImageView imageView = new ImageView(this);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageResource(R.mipmap.xxx1);
webPlayer.setThumbImageView(imageView);
resolveNormalVideoUI();
//外部辅助的旋转,帮助全屏
orientationUtils = new OrientationUtils(this, webPlayer);
//初始化不打开外部的旋转
orientationUtils.setEnable(false);
webPlayer.setIsTouchWiget(true);
//关闭自动旋转
webPlayer.setRotateViewAuto(false);
webPlayer.setLockLand(false);
webPlayer.setShowFullAnimation(false);
webPlayer.setNeedLockFull(true);
//detailPlayer.setOpenPreView(true);
webPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//直接横屏
orientationUtils.resolveByClick();
//第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
webPlayer.startWindowFullscreen(WebDetailActivity.this, true, true);
}
});
webPlayer.setStandardVideoAllCallBack(new SampleListener() {
@Override
public void onPrepared(String url, Object... objects) {
super.onPrepared(url, objects);
//开始播放了才能旋转和全屏
orientationUtils.setEnable(true);
isPlay = true;
}
@Override
public void onAutoComplete(String url, Object... objects) {
super.onAutoComplete(url, objects);
}
@Override
public void onClickStartError(String url, Object... objects) {
super.onClickStartError(url, objects);
}
@Override
public void onQuitFullscreen(String url, Object... objects) {
super.onQuitFullscreen(url, objects);
if (orientationUtils != null) {
orientationUtils.backToProtVideo();
}
}
});
webPlayer.setLockClickListener(new LockClickListener() {
@Override
public void onClick(View view, boolean lock) {
if (orientationUtils != null) {
//配合下方的onConfigurationChanged
orientationUtils.setEnable(!lock);
}
}
});
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
webView.loadUrl("https://www.baidu.com");
webTopLayout.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (!webPlayer.isIfCurrentIsFullscreen() && scrollY >= 0 && isPlay) {
if (scrollY > webPlayer.getHeight()) {
//如果是小窗口就不需要处理
if (!isSamll) {
isSamll = true;
int size = CommonUtil.dip2px(WebDetailActivity.this, 150);
webPlayer.showSmallVideo(new Point(size, size), true, true);
orientationUtils.setEnable(false);
}
} else {
if (isSamll) {
isSamll = false;
orientationUtils.setEnable(true);
//必须
webTopLayoutVideo.postDelayed(new Runnable() {
@Override
public void run() {
webPlayer.hideSmallVideo();
}
}, 50);
}
}
webTopLayoutVideo.setTranslationY((scrollY <= webTopLayoutVideo.getHeight()) ? -scrollY : -webTopLayoutVideo.getHeight());
}
}
});
}
use of android.support.v4.widget.NestedScrollView in project SmartRefreshLayout by scwang90.
the class WeiboPracticeActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_practice_weibo);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
// 状态栏透明和间距处理
StatusBarUtil.immersive(this);
StatusBarUtil.setPaddingSmart(this, toolbar);
final View parallax = findViewById(R.id.parallax);
final View buttonBar = findViewById(R.id.buttonBarLayout);
final NestedScrollView scrollView = (NestedScrollView) findViewById(R.id.scrollView);
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
findViewById(R.id.attention).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(view.getContext(), "点击了关注", Toast.LENGTH_SHORT).show();
}
});
findViewById(R.id.leaveword).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(view.getContext(), "点击了留言", Toast.LENGTH_SHORT).show();
}
});
refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
refreshLayout.finishRefresh(3000);
}
@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
refreshLayout.finishLoadMore(2000);
}
@Override
public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
mOffset = offset / 2;
parallax.setTranslationY(mOffset - mScrollY);
toolbar.setAlpha(1 - Math.min(percent, 1));
}
});
scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
private int lastScrollY = 0;
private int h = DensityUtil.dp2px(170);
private int color = ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary) & 0x00ffffff;
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (lastScrollY < h) {
scrollY = Math.min(h, scrollY);
mScrollY = scrollY > h ? h : scrollY;
buttonBar.setAlpha(1f * mScrollY / h);
toolbar.setBackgroundColor(((255 * mScrollY / h) << 24) | color);
parallax.setTranslationY(mOffset - mScrollY);
}
lastScrollY = scrollY;
}
});
buttonBar.setAlpha(0);
toolbar.setBackgroundColor(0);
}
use of android.support.v4.widget.NestedScrollView in project SmoothRefreshLayout by dkzwm.
the class QuickConfigAutoRefreshUtil method verticalScrollToEdge.
private void verticalScrollToEdge(final boolean toTop, boolean useSmoothScroll) {
if (mTargetView instanceof ScrollView) {
ScrollView scrollView = (ScrollView) mTargetView;
if (scrollView.getChildCount() > 0) {
if (useSmoothScroll) {
scrollView.smoothScrollTo(0, toTop ? 0 : scrollView.getHeight());
} else {
scrollView.scrollTo(0, toTop ? 0 : scrollView.getHeight());
}
}
} else if (mTargetView instanceof AbsListView) {
AbsListView absListView = (AbsListView) mTargetView;
if (absListView.getChildCount() > 0) {
if (useSmoothScroll) {
absListView.smoothScrollToPosition(toTop ? 0 : absListView.getAdapter().getCount() - 1);
} else {
absListView.setSelection(toTop ? 0 : absListView.getAdapter().getCount() - 1);
}
}
} else if (mTargetView instanceof NestedScrollView) {
NestedScrollView scrollView = (NestedScrollView) mTargetView;
if (useSmoothScroll) {
scrollView.smoothScrollTo(0, toTop ? 0 : scrollView.getHeight());
} else {
scrollView.scrollTo(0, toTop ? 0 : scrollView.getHeight());
}
} else {
try {
if (mTargetView instanceof RecyclerView) {
RecyclerView recyclerView = (RecyclerView) mTargetView;
if (recyclerView.getChildCount() > 0) {
if (useSmoothScroll) {
recyclerView.smoothScrollToPosition(toTop ? 0 : recyclerView.getAdapter().getItemCount() - 1);
} else {
recyclerView.scrollToPosition(toTop ? 0 : recyclerView.getAdapter().getItemCount() - 1);
}
}
return;
}
} catch (NoClassDefFoundError e) {
// ignore exception
}
if (useSmoothScroll) {
cancelAnimator();
final float distance;
if (toTop)
distance = mTargetView.getScrollY();
else
distance = mTargetView.getHeight() - mTargetView.getScrollY();
mAnimator = ObjectAnimator.ofInt(mTargetView, "scrollY", mTargetView.getScrollY(), toTop ? 0 : mTargetView.getHeight());
DisplayMetrics dm = mTargetView.getResources().getDisplayMetrics();
mAnimator.setDuration((long) (distance / dm.heightPixels * 200));
mAnimator.start();
mAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mNeedToTriggerRefresh = false;
mNeedToTriggerLoadMore = false;
}
@Override
public void onAnimationCancel(Animator animation) {
mNeedToTriggerRefresh = false;
mNeedToTriggerLoadMore = false;
}
});
} else {
cancelAnimator();
mTargetView.scrollTo(mTargetView.getScrollX(), toTop ? 0 : mTargetView.getHeight());
}
}
}
use of android.support.v4.widget.NestedScrollView in project CollapsingRefresh by ckrgithub.
the class RefreshContentWrapper method setupComponent.
@Override
public void setupComponent(RefreshKernel kernel, View fixedHeader, View fixedFooter) {
this.findScrollableView(mContentView, kernel);
try {
if (mScrollableView instanceof RecyclerView) {
RecyclerViewScrollComponent component = new RecyclerViewScrollComponent(kernel);
component.attach((RecyclerView) mScrollableView);
}
} catch (Throwable ignored) {
}
try {
if (mScrollableView instanceof NestedScrollView) {
NestedScrollViewScrollComponent component = new NestedScrollViewScrollComponent(kernel);
component.attach((NestedScrollView) mScrollableView);
}
} catch (Throwable ignored) {
}
if (mScrollableView instanceof AbsListView) {
AbsListViewScrollComponent component = new AbsListViewScrollComponent(kernel);
component.attach(((AbsListView) mScrollableView));
} else if (Build.VERSION.SDK_INT >= 23 && mScrollableView != null) {
Api23ViewScrollComponent component = new Api23ViewScrollComponent(kernel);
component.attach(mScrollableView);
}
if (fixedHeader != null || fixedFooter != null) {
mFixedHeader = fixedHeader;
mFixedFooter = fixedFooter;
FrameLayout frameLayout = new FrameLayout(mContentView.getContext());
kernel.getRefreshLayout().getLayout().removeView(mContentView);
ViewGroup.LayoutParams layoutParams = mContentView.getLayoutParams();
frameLayout.addView(mContentView, MATCH_PARENT, MATCH_PARENT);
kernel.getRefreshLayout().getLayout().addView(frameLayout, layoutParams);
mContentView = frameLayout;
// TODO: 2017/10/3 头部处理
if (fixedHeader != null) {
fixedHeader.setClickable(true);
ViewGroup.LayoutParams lp = fixedHeader.getLayoutParams();
ViewGroup parent = (ViewGroup) fixedHeader.getParent();
int index = parent.indexOfChild(fixedHeader);
parent.removeView(fixedHeader);
lp.height = measureViewHeight(fixedHeader);
parent.addView(new Space(mContentView.getContext()), index, lp);
frameLayout.addView(fixedHeader);
}
if (fixedFooter != null) {
fixedFooter.setClickable(true);
ViewGroup.LayoutParams lp = fixedFooter.getLayoutParams();
ViewGroup parent = (ViewGroup) fixedFooter.getParent();
int index = parent.indexOfChild(fixedFooter);
parent.removeView(fixedFooter);
FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(lp);
lp.height = measureViewHeight(fixedFooter);
parent.addView(new Space(mContentView.getContext()), index, lp);
flp.gravity = Gravity.BOTTOM;
frameLayout.addView(fixedFooter, flp);
}
}
}
Aggregations