我正在尝试将RecyclerView
列表集中在屏幕上。这将是一个单一的列表,所以我将使用LinearLayoutManager
(LLM)。然而,使用 LLM 它不会集中项目,它在横向模式下看起来像这样:
XML 代码如下所示:
<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>
在 Android Studio 的预览版上,它看起来不错,但在应用程序上,它不是。我设法通过将 LLM 更改为GridLayoutManager
仅包含一列的 a 来修复它。但它看起来很丑。
有谁知道发生了什么?谢谢。