Search code examples
androidgridviewimageviewanimator

ImageView edges get cut off while rotating in GridView


I'm making memory game in Android. I decided to use GridView with adapter, which inflates image inside every of cell.

Problem is that images in first row get cut of while 3D rotating around y axis, like this: take a look

This does not happen with images in last row. Only way I managed to avoid this behaviour was to increase padding for each image, but that changes by layout too much. I also tried adding top padding and/or margin to GridView, but that did not help. Is there any way to make images in first rotate without this issue? Here is my layout code:

  <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    tools:context="com.example.alen.matchinggameaddiko.activities.GameActivity">
    <ImageView
        android:id="@+id/imageView"
        android:layout_width="150dp"
        android:layout_height="0px"
        android:layout_marginLeft="26dp"
        android:layout_marginTop="0dp"
        android:src="@drawable/addiko_logo_white"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <GridView
        android:id="@+id/grid_game"
        android:layout_width="0px"
        android:layout_height="0px"
        android:layout_marginBottom="10dp"
        android:layout_marginEnd="@dimen/gridImagesMarginLeft"
        android:layout_marginStart="@dimen/gridImagesMarginRight"
        android:numColumns="4"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView" />
</android.support.constraint.ConstraintLayout>

Thanks!


Solution

  • Have you tried ViewGroup.setClipChildren(false)? The rotation looks like it's leaving the ViewGroup's bounds.