美文网首页
Android RecyclerView Child设置为正方

Android RecyclerView Child设置为正方

作者: zyguo | 来源:发表于2019-07-31 17:39 被阅读0次

    对于使用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的宽高比

    相关文章

      网友评论

          本文标题:Android RecyclerView Child设置为正方

          本文链接:https://www.haomeiwen.com/subject/jfpcdctx.html