askNilesh / carousel-layout-using-viewPager2

70 stars 9 forks source link

Transparent Layout Problem #5

Closed OnurSerbes closed 2 years ago

OnurSerbes commented 2 years ago

I am using this viewPager project but ı didn't understand why those views are transparent. I checked both XML and JAVA file but ı couldn't find the problem.

You can find the codes that ı'm using:

I convert to Kotlin

`myViewPager2 = findViewById(R.id.viewpager);

  view.viewpager.orientation = ViewPager2.ORIENTATION_HORIZONTAL;
    view.viewpager.adapter = myAdapter;
    view.viewpager.offscreenPageLimit = 3;

    val pageMargin = resources.getDimensionPixelOffset(R.dimen.pageMargin).toFloat()
    val pageOffset = resources.getDimensionPixelOffset(R.dimen.offset).toFloat()

    view.viewpager.setPageTransformer(ViewPager2.PageTransformer { page: View, position: Float ->
        val myOffset = position * -(2 * pageOffset + pageMargin)
        when {
            position < -1 -> {
                page.translationX = -myOffset
            }
            position <= 1 -> {
                val scaleFactor =
                    max(0.7f, 1 - abs(position - 0.14285715f))
                page.translationX = myOffset
                page.scaleY = scaleFactor
                page.alpha = scaleFactor
            }
            else -> {
                page.alpha = 0f
                page.translationX = myOffset
            }
        }
    })`

and here is the XML

<androidx.viewpager2.widget.ViewPager2 android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="200dp" android:layout_marginTop="5dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.19" />

askNilesh commented 2 years ago

@OnurSerbes can you please add some screenshots for the problem?

OnurSerbes commented 2 years ago

6404ed96-2799-47f9-b6af-1c22ce34cdc5

as you can see in here transparency giving me a problem, but in the codes ı couldn't see anything like that. There is not a code about transparenct in my cards as well

askNilesh commented 2 years ago

@OnurSerbes Can you please create demo project for the same and upload it on github so ican try to reporduce the issue

OnurSerbes commented 2 years ago

@askNilesh here you can find a demo about how ı just did https://github.com/OnurSerbes/kotlin-viewpager-swipecards

askNilesh commented 2 years ago

@OnurSerbes how about this

is this match with your requirement

askNilesh commented 2 years ago

@OnurSerbes just update repository code for this please checkout once and let me know if you face any issue

OnurSerbes commented 2 years ago

c679c708-7430-474e-ae76-b4b4ac50ae20 @askNilesh if you use it with correct "next_item_visible_width" dimen, cards are not overlap. I changed it for the check transperancy. As you can see left side is works okay but card is fading at the right side of the selected card and the upcoming card can still visible when overlaps . But the general transparant problem is solved ı guess. Nice job