Sla*_*neR 4 android android-layout android-recyclerview
第一张图描述我想要什么,第二张图是我得到的。
黑色矩形表示RecyclerView
,深红色表示它的项目。海军是ImageView
。
我在 recyclerview 所属的父视图组上尝试了 clipChildren。
有什么办法可以实现吗?(我也试过动画)
val animation = TranslateAnimation(
Animation.ABSOLUTE, 0f,
Animation.ABSOLUTE, 0f,
Animation.ABSOLUTE, 0f,
Animation.ABSOLUTE, -dpToPixel(21f, itemView.context)
)
animation.duration = 0
imageView.startAnimation(animation)
Run Code Online (Sandbox Code Playgroud)
- - 编辑 - -
活动布局
val animation = TranslateAnimation(
Animation.ABSOLUTE, 0f,
Animation.ABSOLUTE, 0f,
Animation.ABSOLUTE, 0f,
Animation.ABSOLUTE, -dpToPixel(21f, itemView.context)
)
animation.duration = 0
imageView.startAnimation(animation)
Run Code Online (Sandbox Code Playgroud)
ViewHolder 布局
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@android:color/black"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
请注意,我不能提供超过 60dp 的高度,并且内部项目具有固定高度 (50dp)。
在您的示例中,视图持有者布局包含在RecyclerView 中,而RecyclerView包含在 a_ConstraintLayout_ 中。
ConstraintLayout
----> RecyclerView
--------> ConstraintLayout (view holder)
------------> ImageView
android:clipChildren
定义孩子是否被限制在其边界内绘制。
你想视图持有人能够绘制的ImageView的观点持有人的范围之外,并在RecyclerView绘制的边界的观点持有者外RecyclerView。为此,您需要android:clipChildren="false"
在RecyclerView 和顶级ConstraintLayout 上进行设置。
归档时间: |
|
查看次数: |
1770 次 |
最近记录: |