I am trying to centralize a RecyclerView
list in the screen. Its going to be a single list, so I will use the LinearLayoutManager
(LLM).
However using the LLM its not centralizing the items, and it looks like this on the landscape mode:
The XML code looks like this:
<FrameLayout 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:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/recipe_card"
android:layout_gravity="center"
android:layout_width="400dp"
android:layout_height="186dp"
style="@style/CardViewStyle">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/recipe_image"
android:layout_width="120dp"
android:layout_height="163dp"
app:srcCompat="@mipmap/ic_pan"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
tools:layout_editor_absoluteY="3dp" />
<TextView
android:id="@+id/recipe_name"
android:layout_width="250dp"
android:layout_height="119dp"
android:text="TextView"
app:layout_constraintLeft_toRightOf="@+id/recipe_image"
android:layout_marginLeft="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp" />
<TextView
android:id="@+id/recipe_servings"
android:layout_width="164dp"
android:layout_height="32dp"
android:text="TextView"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/recipe_name"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintLeft_toRightOf="@+id/recipe_image"
android:layout_marginLeft="94dp"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
On the Android Studio's Preview, it looks fine, but on the app, it does not.
I manage to fix it by changing the LLM for a GridLayoutManager
with only one column. But it looks ugly.
Does anyone knows what is going on? Thanks.