How to adjust empty cell in grid layout in android studio?

87 views Asked by At

I am working on android project using kotlin and xml. I have design a screen in where there are six menu like below initial view

When I set visibility gone to the menu named "Chuti". Then the screen look likes below.. Problematic view

But my expected screen will be look like.. my expected screen

Here the activity file:

 class ChutiActivity : AppCompatActivity() {
   private lateinit var binding : ActivityChutiBinding
   override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = ActivityChutiBinding.inflate(layoutInflater)
    setContentView(binding.root)

    binding.chutiTV.visibility = View.GONE
    }
}

Please, help me.

1

There are 1 answers

4
Masoud On

you must remove the item and notifidatasetChange() your adapter. Add the below code to your adapter :

   YourModel item = getItem(position);  
   if(position == your_remove_item_index){   
     remove(item);
   }
`