0% found this document useful (0 votes)
33 views3 pages

Sampl

The document contains code for implementing a slider view in Android. It defines the layout for the slider view and individual slider items. It also includes a SliderAdapter class to populate the slider items from image and text arrays. On create, the activity gets a reference to the slider view, populates the adapter with image and text data, and sets properties like the transform animation and auto cycling.

Uploaded by

Vinayak Lokhande
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Sampl

The document contains code for implementing a slider view in Android. It defines the layout for the slider view and individual slider items. It also includes a SliderAdapter class to populate the slider items from image and text arrays. On create, the activity gets a reference to the slider view, populates the adapter with image and text data, and sets properties like the transform animation and auto cycling.

Uploaded by

Vinayak Lokhande
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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