[Android] carousel – slide picture Title Focus

V4 package provided by Google, viewpager

In the layout file, first add the < Android. Support. V4. View. Viewpager / > control, which is only a rotation area

In the layout file, the layout Title Description section

Linear layout, vertical arrangement, background color black translucent, this layout is aligned with the bottom of the viewpager above_ alignBottom=”@id/xxx”

< textview / > center display,

For the smaller part, let go of the empty LinearLayout. The ID is LL_ Points populates it in the code

Get viewpager object

Call setadapter() method of viewpager object, parameter: pageradapter object

Because pageradapter is an abstract class, define a mypageradapter to inherit pageradapter and implement the following methods

Override the getcount () method to return the number of rotations

Override the isviewfromobject() method to return a Boolean value,

Override the instantiateitem () method, add the current view object to the ViewGroup object, and return the current object

Override the destroyitem () method to delete the view at the specified position from the current container

Toggle description title string

Define a string [] array to save the title

Call setonpagerchangelistener() method of viewpager object, parameter: onpagerchangelistener object

Anonymous inner class implementation, override the following methods

OnPageSelected () method, called after page switching, passing in parameters, int index

Onpagescrolled() method, when the page is scrolling

Onpagescrollstatechanged() method, when the page scrolling state changes

Small icon section

Create two new shape files and draw two origin points using XML

Add a node < Shape >, and set the shape to prototype Android: shape = "oval"

Add a size node < size >, set the width and height, Android: width = "Android: height ="

Add a color node < solid >, and set the color Android: color = ""

Under normal circumstances, the gray point, the focus point and the white point are different in color between the two XM files

point.xml

point_ write.xml

Create a new selector file. When the picture is enabled, the white points, when it is unavailable, the gray points, and pictures in different states

Add < selector > node

Add the < item > node, set the picture attribute Android: drawable = "set the status Android: enabled =" true|false "

point_ selector.xml

Cycle the number of large pictures and create an ImageView object,

Call the ImageView object setimageresource() method to set the resource. Parameters: selector file

Call the setlayoutparams() method of the ImageView object to add some margin values to the small icon ImageView object. Parameters: layoutparams object, obtain the linearlayout.layoutparams object, call the rightmargin() method of the layoutparams object, and set the margin value

Call the setenabled() method of the ImageView object to set whether it is available. Parameter: Boolean

Get the LinearLayout object, call the addview () method of the LinearLayout object, and fill in the view of the small icon. Parameter: ImageView object

By default, the first one is the focus. As the picture slides, the focus changes

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