简体   繁体   English

如何在中心制作 recyclerView 的项目?

[英]How can i make items of recyclerView in center?

I want to keep the items in center of recyclerview.我想将项目保留在 recyclerview 的中心。 i have posted an image.我发布了一张图片。 please help me to do that请帮我做那件事

the code of layout布局代码

    <?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="120dp"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_gravity="center_horizontal"
    app:cardCornerRadius="5dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/service_image"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:src="@drawable/washingmachin"
            android:layout_gravity="center_horizontal"/>

        <TextView
            android:id="@+id/service_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Washing Mashing"
            android:layout_gravity="center_horizontal"/>

    </LinearLayout>

</androidx.cardview.widget.CardView>

i want the image of fridge ac laundry and all to keep in center of screen我希望冰箱空调洗衣房的图像以及所有内容都保留在屏幕中央

1]

add添加

android:layout_gravity="center"

to your LinearLayout到您的 LinearLayout

将 android:gravity="center" 设置为文本视图或线性布局都应该有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM