Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

android:id="@+id/sliderview"

android:layout_width="match_parent"
android:layout_height="250dp"
app:sliderScrollTimeInSec="1"
app:sliderAnimationDuration="1000"
app:sliderAutoCycleDirection="back_and_forth"
app:sliderIndicatorRadius="2dp"
app:sliderIndicatorSelectedColor="#5C5858"
app:sliderIndicatorUnselectedColor="#c1c1c1"
app:sliderStartAutoCycle="true"/>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/image"
android:scaleType="fitXY"
android:adjustViewBounds="true"/>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="@drawable/bg_overlay"
android:layout_alignParentBottom="true">

<TextView
android:id="@+id/textDesc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="vinayak"
android:textColor="#fff"
android:textSize="22sp"
android:textStyle="bold"
android:gravity="center"/>

<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">

<gradient
android:startColor="@color/black"
android:endColor="@android:color/transparent"
android:angle="90"/>

</shape>

public class MainActivity extends AppCompatActivity {


private int[] images;
private String[] text;
private SliderAdapter adapter;
private SliderView sliderView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

sliderView = findViewById(R.id.sliderview);
images = new int[]{R.drawable.indiaflag,R.drawable.cp};
text = new String[]{"IndiaFlag","C Programming"};

adapter = new SliderAdapter(images,text);


sliderView.setSliderAdapter(adapter);

sliderView.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
sliderView.setIndicatorAnimation(IndicatorAnimationType.DROP);
sliderView.startAutoCycle();

public class SliderAdapter extends SliderViewAdapter<SliderAdapter.Holder>{

private int []images;


private String[] text;

public SliderAdapter(int[] images, String[] text) {


this.images = images;
this.text = text;
}

@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]);
viewHolder.textView.setText(text[position]);

viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Toast.makeText(, "", Toast.LENGTH_SHORT).show();
}
});
}

@Override
public int getCount() {
return images.length;
}
public class Holder extends SliderViewAdapter.ViewHolder{

private ImageView imageView;


private TextView textView;

public Holder(View itemView) {


super(itemView);

imageView = itemView.findViewById(R.id.image);
textView = itemView.findViewById(R.id.textDesc);
}
}

You might also like