diff --git a/catalog/java/io/material/catalog/carousel/HeroCarouselDemoFragment.java b/catalog/java/io/material/catalog/carousel/HeroCarouselDemoFragment.java index 01d42bd63aa..ed3eecb2c92 100644 --- a/catalog/java/io/material/catalog/carousel/HeroCarouselDemoFragment.java +++ b/catalog/java/io/material/catalog/carousel/HeroCarouselDemoFragment.java @@ -18,6 +18,9 @@ import io.material.catalog.R; +import static com.google.android.material.carousel.CarouselLayoutManager.ALIGNMENT_CENTER; +import static com.google.android.material.carousel.CarouselLayoutManager.ALIGNMENT_START; + import android.os.Bundle; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.SnapHelper; @@ -25,6 +28,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AutoCompleteTextView; +import android.widget.RadioButton; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.google.android.material.carousel.CarouselLayoutManager; @@ -65,8 +69,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle bundle) { MaterialSwitch enableFlingSwitch = view.findViewById(R.id.enable_fling_switch); AutoCompleteTextView itemCountDropdown = view.findViewById(R.id.item_count_dropdown); Slider positionSlider = view.findViewById(R.id.position_slider); + RadioButton startAlignButton = view.findViewById(R.id.start_align); + RadioButton centerAlignButton = view.findViewById(R.id.center_align); - // A start-aligned hero carousel + // A hero carousel RecyclerView heroStartRecyclerView = view.findViewById(R.id.hero_start_carousel_recycler_view); CarouselLayoutManager heroStartCarouselLayoutManager = @@ -135,6 +141,11 @@ public void onStopTrackingTouch(@NonNull Slider slider) { } }); + startAlignButton.setOnClickListener( + v -> heroStartCarouselLayoutManager.setCarouselAlignment(ALIGNMENT_START)); + centerAlignButton.setOnClickListener( + v -> heroStartCarouselLayoutManager.setCarouselAlignment(ALIGNMENT_CENTER)); + heroStartRecyclerView.setAdapter(adapter); adapter.submitList(CarouselData.createItems(), updateSliderRange(positionSlider, adapter)); } diff --git a/catalog/java/io/material/catalog/carousel/res/layout/cat_carousel_hero_fragment.xml b/catalog/java/io/material/catalog/carousel/res/layout/cat_carousel_hero_fragment.xml index 2f2e7c65d9d..26bf233da52 100644 --- a/catalog/java/io/material/catalog/carousel/res/layout/cat_carousel_hero_fragment.xml +++ b/catalog/java/io/material/catalog/carousel/res/layout/cat_carousel_hero_fragment.xml @@ -68,6 +68,27 @@ android:textAppearance="?attr/textAppearanceBodyLarge" android:text="@string/cat_carousel_enable_fling_label"/> + + + + + Draw dividers Enable Snap Enable fling + Start align + Center align Show debug options