Analysis on the method of switching ImageView by Android programming

This paper describes the method of switching ImageView by Android programming. Share with you for your reference, as follows:

Recently, when making the Gobang interface, there needs to be an area to dynamically display the current chess game. Considering the font and realistic effect, I decided to display it with pictures, which is used to dynamically switch the source of ImageView in Java code.

I looked on the Internet. There are several ways:

However, considering the frequent switching of my display area, it is troublesome to use such statements every time, so I found another method, preset the source with XML file, and then call it directly in the code. As follows:

Create a new XML file under res and drawable, with the name as you like. The file content is as follows:

Set the source image and corresponding ID one by one, and then set the properties of ImageView:

Then we can apply it in java files as follows:

If there are many pictures, it is much more convenient to switch with this method.

In addition, we can cooperate

In this way, an ImageView can be displayed and hidden from time to time. In addition, it can switch pictures. In this way, it can display some states with simple behavior and beautiful content.

More readers interested in Android related content can view the special topics of this site: summary of Android graphics and image processing skills, introduction and advanced tutorial of Android development, summary of Android debugging skills and common problem solving methods, summary of Android basic component usage, summary of Android view skills, summary of Android layout skills, and Android control usage summary

I hope this article will help you in Android programming.

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