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

android – 具有起始填充的水平RecyclerView,第1张

概述所以我有一个 ImageView作为背景,并在它上面有一个Horizo​​ntal RecyclerView,这里的事情是我希望RecyclerView开始从屏幕的半填充到左边显示它的项目,这样你就可以在开始时看到完美的背景当您滚动项目时,您将隐藏图像/背景. 注意:检查Play商店以查看我要完成的 *** 作. 所以我有这个工作: <RelativeLayout android:layout_widt 所以我有一个 ImageVIEw作为背景,并在它上面有一个Horizo​​ntal RecyclerVIEw,这里的事情是我希望RecyclerVIEw开始从屏幕的半填充到左边显示它的项目,这样你就可以在开始时看到完美的背景当您滚动项目时,您将隐藏图像/背景.

注意:检查Play商店以查看我要完成的 *** 作.

所以我有这个工作:

<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从右侧开始半屏,但滚动时它不会滚动直到屏幕左侧,它只会隐藏设置填充的位置.

<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>
解决方法 我通常用 ItemDecoration来实现这种效果,而不是使用填充.
public class paddingItemdecoration extends RecyclerVIEw.Itemdecoration {    private final int size;    public paddingItemdecoration(int size) {        this.size = size;    }    @OverrIDe    public voID getItemOffsets(Rect outRect,VIEw vIEw,RecyclerVIEw parent,RecyclerVIEw.State state) {        super.getItemOffsets(outRect,vIEw,parent,state);        // Apply offset only to first item        if (parent.getChildAdapterposition(vIEw) == 0) {            outRect.left += size;        }    }}

然后在设置RecyclerVIEw时:

int size = ... // Get the offset that you wantRecyclerVIEw recyclerVIEw = ...recyclerVIEw.addItemdecoration(new paddingItemdecoration(size));
总结

以上是内存溢出为你收集整理的android – 具有起始填充的水平RecyclerView全部内容,希望文章能够帮你解决android – 具有起始填充的水平RecyclerView所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1134437.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存