Android uses the open source framework android-image-indicator to realize image rotation deployment

The previous blog posts introduced the implementation methods of picture rotation, which are (including hyperlinks):

1. Screen switching using viewflipper in Android

2. Using viewpager to realize screen page switching and page rotation effect in Android

3. Using imageviewswitcher to realize the effect of image switching and rotation navigation in Android

Today, Android image indicator, an open source project in GitHub, is used to simply realize the rotation of the pictures provided by the app and load the network pictures for rotation.

1、 Download project from GitHub

GitHub address: https://github.com/panxw/android-image-indicator

It introduces a simple use example, you can have a look

2、 Import dependent packages

(1) I try to import dependent packages by importing the library in the download file through the import module using Android studio 2,2, but the downloaded project is built using Maven,

Error message during import: error: (2,0) plugin with ID 'com. GitHub. Dcendents. Android Maven' not found. Several solutions have been tried, which can not effectively solve the problem of dependent package import. The second method of importing is recommended

(2) Add the following code directly under dependencies in build. Gradle (module. APP)

compile 'com.panxw.imageindicator:library:1.0.2'

Add an example as follows:

After adding, click the prompt on the interface to synchronize the following.

3、 Demo loading app's own picture (1) layout file is as follows:

(2) The Java implementation code is as follows:

4、 Load network picture

(1) First, customize networkimageindicatorview.class in Java

The network communication framework volley is used to load network pictures into ImageView. The imagerequest is mainly used here,

The imagerequest constructor receives six parameters, representing the following meanings:

The first parameter is the URL address of the image. There is nothing to explain.

The second parameter is the callback of successful image request. Here, we set the returned bitmap parameter to ImageView.

The third and fourth parameters are respectively used to specify the maximum width and height of the allowed picture. If the width or height of the specified network picture is greater than the maximum value here, the picture will be compressed. If it is specified as 0, it means that no matter how large the picture is, it will not be compressed.

The fifth parameter is used to specify the color attribute of the picture. Several constants under bitmap. Config can be used here, including ARGB_ 8888 can show the best color attributes. Each picture pixel occupies a size of 4 bytes, while RGB_ 565 indicates that each picture pixel occupies 2 bytes.

The sixth parameter is the callback when the image request fails. Here, we display a default image in ImageView when the request fails.

(2) The layout presentation file is as follows:

(3) The Java implementation code is as follows:

It is very convenient to use the open source framework. This demonstration is only for the realization of functions. You can optimize the lower interface and achieve the results you want when you have time (my jade photo is quoted in the network loading. Thank you for watching)

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