Android RecyclerView Child设置为正方

2019-07-31  本文已影响0人  zyguo

对于使用GridLayoutManager的Recyclerview来说,想要将item设置为正方形,最简单的办法是使用ConstraintLayout

类似这样:

<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <ImageView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="H,1:1"
            app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>

就可以了
关键是ConstraintLayout的这个属性:

app:layout_constraintDimensionRatio

可以用来设置child的宽高比

上一篇 下一篇

猜你喜欢

热点阅读