Android realizes the effect of rotating picture

Time:2021-10-24

This example shares the specific code for Android to realize the effect of rotating picture for your reference. The specific contents are as follows

1. Put the code in LinearLayout,


<com.jude.rollviewpager.RollPagerView
        android:id="@+id/roll_view_pager"
        android:layout_width="match_parent"
        android:layout_height="180dp"
        android:layout_marginTop="56dp"

         />

2. Add dependency in build.gradle

//Rotation chart
    implementation 'com.jude:rollviewpager:1.2.9'

3. Add code to Java class:

public class RecommendFragment extends Fragment {
    private RollPagerView mRollPagerView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_recommend,container,false);
        mRollPagerView= view.findViewById(R.id.roll_view_pager);
        //Set playback interval
        mRollPagerView.setPlayDelay(3000);
        //Set transparency
        mRollPagerView.setAnimationDurtion(500);
        //Set up adapter
        mRollPagerView.setAdapter(new TestNormalAdapter());
        //Set dot indicator color
        mRollPagerView.setHintView(new ColorPointHintView(getContext(), Color.YELLOW, Color.WHITE));
        return view;
    }
    //Custom adapter
    private class TestNormalAdapter extends StaticPagerAdapter {
        //Photos required for rotation
        private int[] imgs={
                R. Drawable.lb1, // three rotation pictures
                R.drawable.lb1,
                R.drawable.lb3,
        };
        @Override
        public View getView(ViewGroup container, int position) {
            ImageView view=new ImageView(container.getContext());
            view.setImageResource(imgs[position]);
            view.setScaleType(ImageView.ScaleType.CENTER_CROP);
            view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));
            return view;
        }
        @Override
        public int getCount() {
            return imgs.length;
        }
    };

4. Add code in gradle.properties:


android.overridePathCheck=true

5. Don’t panic if you don’t see the diagram in XML. The diagram will come out by itself when running

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

Recommended Today

SQL statement of three-level linkage of provinces, cities and counties

The first is the table creation statement Copy codeThe code is as follows: CREATE TABLE `t_address_province` ( `id` INT AUTO_ Increment primary key comment ‘primary key’,`Code ` char (6) not null comment ‘province code’,`Name ` varchar (40) not null comment ‘province name’)Engine = InnoDB default charset = utf8 comment = ‘province information table’; CREATE TABLE […]