I have created this layout for a tablet design. However, the text is not aligned in the centre.
This is my xml code.
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
card_view:cardCornerRadius="4dp"
android:layout_margin="5dp"
android:layout_alignParentTop="false"
android:layout_centerHorizontal="false"
android:layout_gravity="center_horizontal">
<RelativeLayout
android:background="@color/colorPrimaryDark"
android:layout_width="300dp"
android:layout_height="200dp"
android:gravity="center_horizontal"
>
<TextView
android:id="@+id/recipe_name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textAlignment="center"
android:gravity="center"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="#fff"
android:textSize="24sp"
tools:text="sample text" />
</RelativeLayout>
</android.support.v7.widget.CardView>
Any ideas?
Try :
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
card_view:cardCornerRadius="4dp"
android:layout_margin="5dp"
android:layout_alignParentTop="false"
android:layout_centerHorizontal="false"
android:layout_gravity="center_horizontal">
<RelativeLayout
android:background="@color/colorPrimaryDark"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_gravity="center"
>
<TextView
android:id="@+id/recipe_name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textAlignment="center"
android:gravity="center"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="#fff"
android:textSize="24sp"
tools:text="sample text" />
</RelativeLayout>
</android.support.v7.widget.CardView>