2020-09-01 杂记(Android)

瀑布流效果可以用StaggeredGridLayoutManager来实现

Staggered本身有交错的意思

实现瀑布流效果的时候, 需要一个ViewHolder占满一整行, 该怎么做呢?

        override fun onViewAttachedToWindow(holder: BaseViewHolder) {
    
    
            super.onViewAttachedToWindow(holder)
            val lp = holder.itemView.layoutParams
            if (lp is StaggeredGridLayoutManager.LayoutParams) {
    
    
                lp.isFullSpan = (holder is BaseRecyclerViewAdapter.DefaultEmptyViewHolder) or (holder is BaseRecyclerViewAdapter.ErrorViewHolder) or
                        (holder is BaseRecyclerViewAdapter.LoadingViewHolder)
            }
        }

ARouter框架没有实现Fragment的startActivityResult, 该怎么做呢?

                        val post = ARouter.getInstance().build(ARouterPath.ACTIVITY_AT_USER)
                                .withInt(IntentConstant.USER_ID, accountModel.user.value?.id ?: 0)
                                .withInt(IntentConstant.FEED_ID, viewModel.feedId)
                        LogisticsCenter.completion(post)
                        val intent = Intent(requireActivity(), post.destination).apply {
    
    
                            this.putExtras(post.extras)
                        }
                        startActivityForResult(intent, REQUEST_CODE)

要多用DialogFragment

DialogFragment中, 如果需要对弹出动画, 背景等作出改变, 需要设置对应的window

        val window = dialog?.window
        val layoutParams = window?.attributes
        layoutParams?.width = WindowManager.LayoutParams.MATCH_PARENT
        layoutParams?.height = WindowManager.LayoutParams.WRAP_CONTENT
        window?.setGravity(Gravity.BOTTOM)
        window?.setWindowAnimations(R.style.dialog_from_bottom_anim)
        window?.attributes = layoutParams
        window?.setBackgroundDrawableResource(android.R.color.transparent)

猜你喜欢

转载自blog.csdn.net/weixin_43662090/article/details/108334344