'Carousel with rounded corners
Is there the possibility of making rounded corners on carousel in Android Studio?
I used a background but it doesn't work
<com.synnapps.carouselview.CarouselView
android:background="@drawable/radius_fond"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:id="@+id/carouselView"
android:layout_width="match_parent"
android:layout_height="200dp"
app:fillColor="@color/neutre30"
app:pageColor="@color/neutre"
app:radius="6dp"
android:layout_marginTop="30dp"
app:slideInterval="4000"
app:strokeColor="#FF777777"
app:strokeWidth="1dp"/>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/fond">
</solid>
<corners android:radius="12dp"></corners>
</shape>
I then used some code to make the corner radius. It works but for a moment the square photo appears and then the corners become round
var imageListener: ImageListener = object : ImageListener {
override fun setImageForPosition(position: Int, imageView: ImageView) {
// You can use Glide or Picasso here
val transformation: Transformation = RoundedTransformationBuilder()
.cornerRadiusDp(12f)
.oval(false)
.build()
Picasso.get().load(sampleImages[position])
.fit()
.transform(transformation)
.into(imageView)
}
}
do you have any other solution?
Thanks
Solution 1:[1]
The CarouselView library has an implmentation for a viewListener as follows
public class SampleCarouselViewActivity extends AppCompatActivity {
CarouselView customCarouselView;
int NUMBER_OF_PAGES = 5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_carousel_view);
customCarouselView = (CarouselView) findViewById(R.id.customCarouselView);
customCarouselView.setPageCount(NUMBER_OF_PAGES);
// set ViewListener for custom view
customCarouselView.setViewListener(viewListener);
}
ViewListener viewListener = new ViewListener() {
@Override
public View setViewForPosition(int position) {
View customView = getLayoutInflater().inflate(R.layout.view_custom, null); // put the value of the XML of how you want your view to look like
//set view attributes here
return customView;
}
};
Solution 2:[2]
You can add custom layout as already mentioned in documentation.
or
For simple solution you can add Cardview as parent of CarouselView
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="200dp"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.synnapps.carouselview.CarouselView
android:id="@+id/carouselView"
android:layout_width="match_parent"
android:layout_height="200dp"
app:fillColor="#FFFFFFFF"
app:pageColor="#00000000"
app:radius="6dp"
app:slideInterval="3000"
app:strokeColor="#FF777777"
app:strokeWidth="1dp"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Narendra_Nath |
| Solution 2 | Android Geek |


