0

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!

Alen Kopic
  • 121
  • 1
  • 1
  • 8

2 Answers2

4

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

Submersed
  • 8,810
  • 2
  • 30
  • 38
  • Hi! Yes, it helped a lot, thanks. Later it led me to this solution, for example: https://stackoverflow.com/questions/22930626/clipchildren-is-not-working – Alen Kopic Feb 16 '18 at 21:31
  • Feel free to accept if it answered your question, or clarify otherwise. :) – Submersed Feb 16 '18 at 21:34
2

In a RecyclerView that I had the same issue, what worked was adding android:clipChildren="false" in the RecyclerView and android:clipToPadding="false" in the root layout of the adapter of the RecyclerView.

steliosf
  • 3,669
  • 2
  • 31
  • 45