Android component gallery and GridView example explanation

Android gallery and GridView components:

Gallery

Gallery is a layout component whose internal elements can scroll horizontally and locate the currently selected child elements in its center.

Let's look at the running effect of the example directly.

The following is the code, and the relevant explanations are put in the code.

1. Create a new project hellogallery

2. Copy wallpaper_ 0.jpg…wallpaper_ 9.jpg 10 picture files to RES / drawable directory

3、res/layout/main. The contents of the XML file are as follows:

Among them, we use FrameLayout to realize the superposition effect, ImageView to display the large picture, gallery to display the gallery, and Android: spacing = "5dp" attribute is used to set the interval between elements.

4. Create a new attrs The XML content is as follows:

5. In mainhellogallery The contents in Java are as follows:

When we click a picture, the picture of the child element will be displayed in the ImageView component on the next layer. Interested students can learn about the inheritance relationship of AdapterView:

The above is the introduction to Android gallery and GridView components. We will continue to supplement relevant knowledge in the future. Thank you for your support for this site!

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
分享
二维码
< <上一篇
下一篇>>