🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / Android RMOS / image slider resim animasyon yapma

1-) Android RMOS - image slider resim animasyon yapma

 

MAİNFRAGMENT.JAVA VEYA MAİNACTİVİTY.JAVA

 

SliderView sliderView;
int[] images = {R.drawable.a1,
        
R.drawable.a2,
        
R.drawable.a3,
        
R.drawable.a4,
        
R.drawable.a5,
        
R.drawable.a6};
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    
super.onActivityCreated(savedInstanceState);


    
sliderView =  getView().findViewById(R.id.image_slider);

    
SliderAdapter sliderAdapter = new SliderAdapter(images);

    
sliderView.setSliderAdapter(sliderAdapter);
    
sliderView.setIndicatorAnimation(IndicatorAnimationType.WORM);
    
sliderView.setSliderTransformAnimation(SliderAnimations.DEPTHTRANSFORMATION);
    
sliderView.startAutoCycle();
}

 

Slider_item.xml

 

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    
android:layout_width="match_parent"
    
android:layout_height="match_parent"
    
xmlns:app="http://schemas.android.com/apk/res-auto">
        <
com.google.android.material.imageview.ShapeableImageView
            
android:layout_width="match_parent"
            
android:layout_height="match_parent"
            
android:id="@+id/image_view"
            
android:scaleType="centerCrop"
            
android:padding="10dp"
            
android:adjustViewBounds="true"

            
app:shapeAppearanceOverlay="@style/roundedImageView"
            
/>
</
androidx.constraintlayout.widget.ConstraintLayout>

 

Strings.xml

 

<style name="roundedImageView" parent="">
    <
item name="cornerFamily">rounded</item>
    <
item name="cornerSize">8dp</item>
</
style>

 

 

Anasayfa.xml

 

<com.smarteist.autoimageslider.SliderView

    
android:id="@+id/image_slider"
    
android:layout_width="match_parent"
    
android:layout_height="300dp"
    
android:layout_margin="5dp"
    
app:sliderAnimationDuration="600"
    
app:sliderAutoCycleDirection="back_and_forth"
    
app:sliderAutoCycleEnabled="true"
    
app:sliderIndicatorAnimationDuration="600"
    
app:sliderIndicatorGravity="center_horizontal|bottom"
    
app:sliderIndicatorMargin="15dp"
    
app:sliderIndicatorOrientation="horizontal"
    
app:sliderIndicatorPadding="3dp"
    
app:sliderIndicatorRadius="2dp"
    
app:sliderIndicatorSelectedColor="#5A5A5A"
    
app:sliderIndicatorUnselectedColor="#FFF"
    
app:sliderScrollTimeInSec="2"
    
app:sliderStartAutoCycle="true" />

 

 

SliderAdapter .java

 

implementation 'com.github.smarteist:autoimageslider:1.4.0'

 

package com.rmos.rmosguestx.Anasayfa;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.rmos.rmosguestx.R;
import com.smarteist.autoimageslider.SliderViewAdapter;

public class SliderAdapter extends SliderViewAdapter<SliderAdapter.Holder> {
    
int[] images;

    
public SliderAdapter(int[] images) {
        
this.images = images;
    }

    
@Override
    
public Holder onCreateViewHolder(ViewGroup parent) {

        
View view = LayoutInflater.from(parent.getContext())
                .inflate(
R.layout.slider_item, parent, false);
        
return new Holder(view);
    }

    
@Override
    
public void onBindViewHolder(Holder viewHolder, int position) {

        viewHolder.
imageView.setImageResource(images[position]);
    }

    
@Override
    
public int getCount() {
        
return images.length;
    }

    
public class Holder extends SliderViewAdapter.ViewHolder {
        
ImageView imageView;

        
public Holder(View itemView) {
            
super(itemView);
            
imageView = itemView.findViewById(R.id.image_view);
        }
    }
}

 

kaynak : https://github.com/foxandroid/imageslider

 

 

 2022 Ocak 06 Perşembe
 341