Detailed explanation of how to use the gallery view of Android advanced components

Gallery view indicates that the content can be displayed horizontally, and the picture can be directly dragged by your fingers. It is generally used to browse the picture. The selected option is located in the middle, and the information can be displayed in response to events. When using the gallery view, you first need to add the gallery component on the screen, which is usually added in the XML layout file using the < Gallery > tag. The basic syntax is as follows:

< Gallery attribute list > < / gallery >

The XML attribute table supported by the gallery component is as follows:

Android: animationduration is used to set the animation duration during list switching. Android: gravity is used to set the control method. Android: spacing is used to set the spacing between lists. Android: unselectedalpha is used to set the transparency of unselected list items

To use the gallery view, you also need to use the adapter to provide the data to be displayed. You usually use the baseadapter class to provide data for the gallery component. The following is a specific example to demonstrate how to provide the pictures to be displayed for the gallery component through the baseadapter adapter.

res/layout/main.xml:

In the RES / values directory, create a file named attr.xml, and define a styleable object in the file to combine multiple attributes. Only one Android: galleryitembackground property provided by the system is specified here to set the background of each option. The specific code is as follows: RES / values / attr.xml:

MainActivity:

The effect is shown in the figure:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>