首先,我在
Android中有点新手.
我目前有一个加载片段的活动,在这个片段中,我实例化了一个RecyclerView(水平方向).
这是我目前的布局:
我的主要:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red"
android:orientation="vertical">
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/green">
我的片段:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:background="@color/yellow">
android:id="@+id/fragment_atelier_recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:background="#FFE5E5E5"
android:scrollbarStyle="insideOverlay"
/>
我的RecyclerView适配器的项目布局:
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@color/gray">
android:id="@+id/item_icon"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:layout_gravity="center"
android:contentDescription="icon"/>
我试着在几个小时内垂直居中我的RecyclerView而没有成功(通过使用gravity,layout_centerVertical等……).
也许我错过了关于wrap_content / match_parent或线性/相对规格的内容.
在此先感谢,祝你有个美好的一天:)