Ich bin ein Neuling in Android. Ich bin mir nicht sicher, warum ich meinen Artikel in RecyclerView nicht zentrieren kann.Android Centering Artikel in RecyclerView
Was ich will, ist wie unten Bild: -
Was machen Android ist wie unten Bild: -
Gibt es eine Möglichkeit, Elemente in RecyclerView zu schieben Center? So wird es wie folgt aussehen: -
biete ich auch die Layout-Dateien wie folgt: -
recycler_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/calendar_itemContainer">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="April"
android:id="@+id/calendar_txtMonth"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textColor="#ff58636d"
android:textSize="16sp"
android:gravity="center|center_vertical|center_horizontal"
android:paddingTop="8dp"
android:paddingLeft="12dp"
android:paddingRight="12dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="21"
android:id="@+id/calendar_txtDay"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/calendar_txtMonth"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textColor="#ff58636d"
android:textSize="40sp"
android:layout_marginTop="-10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="5dp"
android:gravity="center|center_vertical|center_horizontal" />
</RelativeLayout>
fragment_calendar.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/calendar_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"
android:background="#ff2c3e50" />
</RelativeLayout>
und die Java-Codes: -
CalendarAdapter mAdapter = new CalendarAdapter(mDataset);
mLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter.setCalendarCallbacks(this);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
selectItem(mCurrentSelectedPosition);
Probieren Sie mit Android: Layout-Schwerkraft = "Center" für das relative Layout und Android: Schwerkraft = "Center" auf die tetviews..hoff es funktioniert. –
@BornToWin bereits versucht, aber immer noch gleich. – skycrew
Versuchen Sie, mit all dem Layout und Textview Breite heraus fill_parent Oder match_parent. –