我想在屏幕上集中RecyclerView
列表。它將成爲一個單子,所以我將使用LinearLayoutManager
(LLM)。 但是使用其不集中的項目的LLM,和它看起來像這樣的風景模式: 使用LinearLayoutManager集中RecyclerView
的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的預覽,它看起來不錯,但在應用程序,它不。 我設法通過只更改一列GridLayoutManager
的LLM來修復它。但它看起來很醜。
有誰知道發生了什麼事? 謝謝。
大衛檢查我的回答 – scienticious
大衛·我的回答能幫助ü大大無處不在你檢查一下嗎? – pouya