Let’s take a look at today’s results:
This article involves some permission application issues, SO I will directly write the first frame of Android photo/video/file selection/get video in the project of the previous chapter (including the full Demo).
The classic analysis
This effect I am using RecyclerView multi-layout with GridLayoutManager() manager to complete the effect
- Red: Layout 1
- Yellow: Layout 2
When you click the yellow button, pull up the gallery, select the image, and add it to Layout 1
When the red layout data == 9, then hide the last yellow layout
Click the bottom button to display all RecyclerView data
This RecyclerView used the adapter is BaseQuickAdapter multi layout
Problems encountered in writing this small project
When a RecyclerView item is hidden through GONE, it can be hidden but still occupies its position
As we all know:
- View. GONE VIEW Hidden, not in position
- The VISIBLE display View
- INVISIBLE View is INVISIBLE
Solution:
- Step 1: Wrap the Item layout with ConstraintLayout
- Step 2 :(code from the network)
// Prevent hidden item from appearing blank
//isVisible true Displays false does not display
//itemView is passed the root layout
private fun setVisibility(isVisible: Boolean, itemView: View) {
val param = RecyclerView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
if (isVisible) {
param.height = ConstraintLayout.LayoutParams.WRAP_CONTENT// Note the use of the root layout type of your layout
param.width = ConstraintLayout.LayoutParams.MATCH_PARENT// Note the use of the root layout type of your layout
itemView.visibility = View.VISIBLE
} else {
param.height = 0
param.width = 0
itemView.visibility = View.GONE
}
itemView.layoutParams = param
}
Copy the code
Why:
Even if it occupies position but sets its width and height to 0, it will not be displayed
This small project is relatively simple, we directly download the code to see ~
The complete code
What do you like?
Net cloud wine level user’s home page
Original is not easy, your praise is the biggest support for me!