May I know if there's any way I can move my current CardView to center horizontal when I launch the activity, code below is from my main activity and I wanted to launch with the 3rd card (which is the middle one). Any help is much appreciated, thanks!
LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView recyclerView = findViewById(R.id.cardRecyclerView);
recyclerView.setLayoutManager(layoutManager);
CardAdapter adapter = new CardAdapter(this, mNames, mImages, mCards);
adapter.getItemId(3);
recyclerView.setAdapter(adapter);
recyclerView.scrollToPosition(2);
Here's my main activity
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
tools:context=".HomeActivity"
android:background="#f2f2f2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/cardRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
and my list layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true">
<androidx.cardview.widget.CardView
android:id="@+id/card"
android:layout_width="300dp"
android:layout_height="500dp"
android:layout_centerInParent="true"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="15dp"
app:cardCornerRadius="60dp"
app:cardElevation="1dp"
app:cardMaxElevation="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/cardImage"
android:layout_width="240dp"
android:layout_height="240dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
app:srcCompat="@android:color/holo_blue_dark" />
<TextView
android:id="@+id/cardText"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="330dp"
android:textAlignment="center"
android:textColor="#FFF"
android:textSize="60sp"
android:textStyle="bold" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
(Sorry if my explanation isn't really clear)
Here's my current results: sample 1
Here's what I'm trying to achieve: sample 2