flexbox-Layout—热门界面+NestedScrollView

flexbox-Layout—热门界面+NestedScrollView_第1张图片
123.png

依赖

查看gethub

布局—设置FlexboxLayout属性



    



for (int i = 0; i < list.size(); i++) {
    final TextView textView = new TextView(getContext());
    textView.setText(list.get(i));
    textView.setTextSize(16);
    textView.setTextColor(Color.WHITE);
    textView.setPadding(dp12, dp9, dp12, dp9);
    Drawable pressed = DrawableUtil.generateDrawable(dp20);
    Drawable normal = DrawableUtil.generateDrawable(dp20);
    textView.setBackgroundDrawable(DrawableUtil.generateSelector(pressed, normal));
    //设置margin
    FlexboxLayout.LayoutParams params = new FlexboxLayout.LayoutParams(FlexboxLayout.LayoutParams.WRAP_CONTENT
            , FlexboxLayout.LayoutParams.WRAP_CONTENT);
    params.leftMargin = dp15;
    params.topMargin = dp15;
    textView.setLayoutParams(params);

    flexboxLayout.addView(textView);

    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ToastUtil.showToast(getContext(), textView.getText().toString());
        }
    });

}

NestedScrollView

//NestedScrollView和ScrollView相比,是能够兼容协调布局的ScrollView,是design包里面的类

NestedScrollView scrollView = new NestedScrollView(getContext());
flowLayout = new FlowLayout(getContext());
int padding = getResources().getDimensionPixelSize(R.dimen.dp15);
//设置padding值
flowLayout.setPadding(padding, padding, padding, padding);

//将recycleview添加到scrollview中
scrollView.addView(flowLayout);

跟着动画滚动

//监听动画值的变化
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
        int animatedValue = (int) animation.getAnimatedValue();
        //设置给控件的高度
        ViewGroup.LayoutParams params = tvDes.getLayoutParams();
        params.height = animatedValue;
        tvDes.setLayoutParams(params);

        //如果当前是展开动画,则需要让ScrollView进行滚动
        //参1--x方向滚动 参2y方向滚动--getMaxScrollAmount()最大滚动距离
        if (isOpen) {
            scrollView.scrollTo(0, scrollView.getMaxScrollAmount());
        }
    }
});

你可能感兴趣的:(flexbox-Layout—热门界面+NestedScrollView)