Gridview with layout (imageview + imagebutton) for every value

前端 未结 2 911
故里飘歌
故里飘歌 2020-12-18 06:12

Is it possible to make a gridview that has instead of a grid of pictures, a grid of pictures with a small imagebutton below every one of them?

2条回答
  •  我在风中等你
    2020-12-18 06:41

    Short answer: Yes. You can have an ImageView and an ImageButton in a GridView.

    Long answer:

    You will naturally have to create a custom GridView for that purpose.

    For example:

    Create an XML which will hold the container GridView, say, grid.xml:

    
    
    

    And, to define the contents of the GridView, create another XML layout which will hold the ImageView and the ImageButton. Say, grid_items.xml:

    
    
    
        
    
            
    
            
            
        
    
    
    

    Finally, if you are familiar with the concept of custom ListViews, with a few modifications, you will be able to implement a custom GridView too. If you are not familiar with custom ListViews or GridViews, follow this tutorial to see how to create a custom GridView: http://www.coderzheaven.com/2012/02/29/custom-gridview-in-android-a-simple-example/. Or use this Google Search for more tutorials on the same.

    An important point here would be, if you need the ImageButton's to do a function when they are clicked, the onClickListener will need to be setup in the Adapter.

提交回复
热议问题