gpt4 book ai didi

android - 具有起始填充的水平 RecyclerView

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:22:08 25 4
gpt4 key购买 nike

所以我有一个 ImageView 作为背景,在它上面有一个 Horizo​​ntal RecyclerView,这里的事情是我希望 RecyclerView 从屏幕左侧的一半填充开始显示它的项目,这样你就可以完美地看到背景在开始和滚动项目时,您会隐藏图像/背景。

注意:检查 Play 商店以查看我要完成的任务。

enter image description here

所以我有这个工作:

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000052"
android:orientation="vertical" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="@drawable/trybg5"
android:layout_gravity="left" />

<HorizontalScrollView
android:id="@+id/frag_home_gallery_recent_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right"
android:scrollbars="none"
android:layout_weight="1"
android:paddingBottom="@dimen/horizontalGallery_content_padding"
android:paddingTop="@dimen/horizontalGallery_content_padding">


<LinearLayout
android:id="@+id/frag_home_gallery_recientes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="150dp" />
</HorizontalScrollView>
</RelativeLayout>

我的观点是以编程方式扩大 Horizo​​ntalScrollView 内的布局,并且效果很好。但随着时间的推移,我决定迁移到 RecyclerView,但现在没有按预期工作。

出现背景,Recycler 开始向右半屏,但滚动时它不会滚动到屏幕左侧,它会隐藏在设置 padding 的位置..

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000052"
android:orientation="vertical" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="@drawable/trybg5"
android:layout_gravity="left" />

<FrameLayout
android:id="@+id/frag_home_gallery_recent_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right"
android:scrollbars="none"
android:layout_weight="1"
android:paddingBottom="@dimen/horizontalGallery_content_padding"
android:paddingTop="@dimen/horizontalGallery_content_padding">

<android.support.v7.widget.RecyclerView
android:background="@drawable/gallery_bg"
android:id="@+id/frag_home_gallery_recientes"
android:scrollbars="none"
android:paddingLeft="150dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

</FrameLayout>
</RelativeLayout>

知道如何在 RecyclerView 中实现这种效果吗?

这是回收器的详细信息:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:id="@+id/discoContainer"
android:background="@drawable/gallery_bg"
android:layout_margin="5dp"
android:padding="2dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/containerDisco"
android:orientation="vertical">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/logoDisco"
android:transitionName="DiscoId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:contentDescription="LogoDisco"
android:windowSharedElementsUseOverlay="false" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="a 600m tuyos"
android:padding="3dp"
android:layout_gravity="center_horizontal"
android:maxLines="1"
android:gravity="center_horizontal"
android:alpha="500"
android:background="#46000000"
android:textColor="@android:color/white"/>
</RelativeLayout>

<TextView
android:id="@+id/logoTexto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Probando"
android:padding="3dp"
android:layout_gravity="center_horizontal"
android:maxLines="1"
android:gravity="center_horizontal"
android:layout_alignBottom="@+id/containerDisco" />

</LinearLayout>


</LinearLayout>

最佳答案

比这简单多了,RecyclerView 已经有了这个功能:只需将 android:clipToPadding="false" 设置为 RecyclerView XML,这样填充物就不会剪掉您的元素。

所以对于你的例子:

<android.support.v7.widget.RecyclerView
android:background="@drawable/gallery_bg"
android:id="@+id/frag_home_gallery_recientes"
android:scrollbars="none"
android:paddingLeft="150dp"
android:clipToPadding="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

关于android - 具有起始填充的水平 RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34295173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com