android-Vertical RecyclerView内部的Horizo​​ntal RecyclerView

android-Vertical RecyclerView内部的Horizo​​ntal RecyclerView,第1张

概述我正在尝试做这样的事情.因此,我的想法是我拥有带有通道的垂直recyclerview,而在通道的第二个位置上,我应该拥有带有重播的水平recyclerview.我不确定该怎么做,我尝试弄乱了Viewholder,并猜想我应该只在自己的channel_details布局中制作一个recyclerview,并在item_channel_detai

我正在尝试做这样的事情.

因此,我的想法是我拥有带有通道的垂直recyclervIEw,而在通道的第二个位置上,我应该拥有带有重播的水平recyclervIEw.

我不确定该怎么做,我尝试弄乱了VIEwholder,并猜想我应该只在自己的channel_details布局中制作一个recyclervIEw,并在item_channel_details中将另一个作成一个item,但是我无法使其工作.

这是我的代码.

ChannelDetailsActivity:

 @OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_channel_details);    ImageVIEw coverPhoto = (ImageVIEw) findVIEwByID(R.ID.image_cover_details);    final HexagonImageVIEw avatarPhoto = (HexagonImageVIEw) findVIEwByID(R.ID.img_hex);    TextVIEw toolbarText = (TextVIEw) findVIEwByID(R.ID.txt_toolbar_Title);    final Bundle b = getIntent().getExtras();    final MNetworkChannel parcelChannel =            b.getParcelable(Const.IntentData.H_CHANNEL_List);    final MVIDeosForChannel parcelVIDeosForChannel = b.getParcelable(Const.IntentData.D_VIDEOS_List);    setChannelsVIEw();    setVIDeosVIEw();}private voID setChannelsVIEw() {    rvRelive = (RecyclerVIEw) findVIEwByID(R.ID.rv_relive_details);    rvRelive.setLayoutManager(new linearlayoutmanager(this, linearlayoutmanager.HORIZONTAL, false));    adapterRelives = new ReliveAdapter();    rvRelive.setAdapter(adapterRelives);    if (getIntent() != null && getIntent().getParcelableExtra(Const.IntentData.D_REliVE_List) != null) {        adapterRelives.setData(((ReliveMainPojo) getIntent().getParcelableExtra(Const.IntentData.D_REliVE_List)).relives);    }}private voID setVIDeosVIEw() {    rvVIDeos = (RecyclerVIEw) findVIEwByID(R.ID.rv_vIDeos);    rvVIDeos.setLayoutManager(new linearlayoutmanager(this, linearlayoutmanager.VERTICAL, false));    adapterVIDeos = new ChannelVIDeosAdapter();    rvVIDeos.setAdapter(adapterVIDeos);    if (getIntent() != null && getIntent().getParcelableExtra(Const.IntentData.D_VIDEOS_List) != null) {        adapterVIDeos.setData(((MVIDeosForChannel) getIntent().getParcelableExtra(Const.IntentData.D_VIDEOS_List)).experIEnce);    }}

ChannelDetails适配器:

public final class ChannelVIDeosAdapter extends RecyclerVIEw.Adapter<ChannelVIDeosAdapter.VIEwHolder> {private List<MVIDeo> data = new ArrayList<>();public ChannelVIDeosAdapter() {}public voID setData(List<MVIDeo> newData) {    if (newData != null && !newData.isEmpty()) {        data = newData;        notifyDataSetChanged();    }}public voID clearData() {    data.clear();    notifyDataSetChanged();}@OverrIDepublic final ChannelVIDeosAdapter.VIEwHolder onCreateVIEwHolder(final VIEwGroup parent, final int vIEwType) {    return new VIEwHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_vIDeo_recycle_tile, parent, false));}@OverrIDepublic final voID onBindVIEwHolder(final ChannelVIDeosAdapter.VIEwHolder holder, final int position) {    final MVIDeo vIDeo = data.get(position);    final String vIDeoBackgroundImageUrl = vIDeo.asset.frame;    final String vIDeoname = vIDeo.name;    ImageLoader.getInstance().displayImage(vIDeoBackgroundImageUrl, holder.coverPhoto, new ImageLoadingListener() {        @OverrIDe        public voID onl oadingStarted(String imageUri, VIEw vIEw) {            holder.vIDeoloading.setVisibility(VIEw.VISIBLE);        }        @OverrIDe        public voID onl oadingFailed(String imageUri, VIEw vIEw, FailReason failReason) {            holder.vIDeoloading.setVisibility(VIEw.GONE);        }        @OverrIDe        public voID onl oadingComplete(String imageUri, VIEw vIEw, Bitmap loadedImage) {            holder.vIDeoloading.setVisibility(VIEw.GONE);        }        @OverrIDe        public voID onl oadingCancelled(String imageUri, VIEw vIEw) {            holder.vIDeoloading.setVisibility(VIEw.GONE);        }    });    holder.vIDeoname.setText(vIDeoname);    holder.itemVIEw.setonClickListener(new VIEw.OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            VIDeoPlayerActivity.StartNewVIDeoPlayerActivity((ChannelDetailsActivity) holder.itemVIEw.getContext(), vIDeo, true);        }    });}@OverrIDepublic final int getItemCount() {    return data.size();}final class VIEwHolder extends RecyclerVIEw.VIEwHolder {    private final ImageVIEw coverPhoto;    private final TextVIEw vIDeoname;    private final Progressbar vIDeoloading;    VIEwHolder(final VIEw itemVIEw) {        super(itemVIEw);        coverPhoto = (ImageVIEw) itemVIEw.findVIEwByID(R.ID.img_thumbnail_background_vIDeo);        vIDeoname = (TextVIEw) itemVIEw.findVIEwByID(R.ID.txt_vIDeo_name);        vIDeoloading = (Progressbar) itemVIEw.findVIEwByID(R.ID.pb_vIDeo_loading);    }}}

重新启动适配器:

public final class ReliveAdapter extends RecyclerVIEw.Adapter<ReliveAdapter.VIEwHolder> {private List<Relive> data = new ArrayList<>();public ReliveAdapter() {}public voID setData(List<Relive> newData) {    if (newData != null && !newData.isEmpty()) {        data = newData;        notifyDataSetChanged();    }}public voID clearData() {    data.clear();    notifyDataSetChanged();}@OverrIDepublic final ReliveAdapter.VIEwHolder onCreateVIEwHolder(final VIEwGroup parent, final int vIEwType) {    return new VIEwHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_relive_recycle_tile, parent, false));}@OverrIDepublic voID onBindVIEwHolder(final ReliveAdapter.VIEwHolder holder, final int position) {    final Relive relive = data.get(position);    final String reliveOwnerIconUrl = relive.owner.asset.large;    final String reliveCoverPhotoUrl = relive.asset.stream.thumbnail;    final String reliveDescription = relive.owner.name;    ImageLoader.getInstance().displayImage(reliveCoverPhotoUrl, holder.backgroundImage, new ImageLoadingListener() {        @OverrIDe        public voID onl oadingStarted(String imageUri, VIEw vIEw) {            holder.imageLoading.setVisibility(VIEw.VISIBLE);        }        @OverrIDe        public voID onl oadingFailed(String imageUri, VIEw vIEw, FailReason failReason) {            holder.imageLoading.setVisibility(VIEw.GONE);        }        @OverrIDe        public voID onl oadingComplete(String imageUri, VIEw vIEw, Bitmap loadedImage) {            holder.imageLoading.setVisibility(VIEw.GONE);            ImageLoader.getInstance().displayImage(reliveOwnerIconUrl, holder.profilePicture, new ImageLoadingListener() {                @OverrIDe                public voID onl oadingStarted(String imageUri, VIEw vIEw) {                    holder.imageLoading.setVisibility(VIEw.VISIBLE);                }                @OverrIDe                public voID onl oadingFailed(String imageUri, VIEw vIEw, FailReason failReason) {                    holder.imageLoading.setVisibility(VIEw.GONE);                }                @OverrIDe                public voID onl oadingComplete(String imageUri, VIEw vIEw, Bitmap loadedImage) {                    holder.imageLoading.setVisibility(VIEw.GONE);                }                @OverrIDe                public voID onl oadingCancelled(String imageUri, VIEw vIEw) {                    holder.imageLoading.setVisibility(VIEw.GONE);                }            });            holder.eyeIcon.setimageResource(R.drawable.relive);        }        @OverrIDe        public voID onl oadingCancelled(String imageUri, VIEw vIEw) {            holder.imageLoading.setVisibility(VIEw.GONE);        }    });    holder.reliveDescription.setText(reliveDescription);    holder.itemVIEw.setonClickListener(new VIEw.OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            RelivePlayerActivity.StartReliveRevIEwActivity((ChannelDetailsActivity) holder.itemVIEw.getContext(), relive.asset.stream.url, relive.experIEnceGuID, relive.guID, holder.getAdapterposition());        }    });}@OverrIDepublic final int getItemCount() {    return data.size();}final class VIEwHolder extends RecyclerVIEw.VIEwHolder {    private final circleimageVIEw profilePicture;    private final ImageVIEw eyeIcon;    private final ImageVIEw backgroundImage;    private final TextVIEw reliveDescription;    private final Progressbar imageLoading;    VIEwHolder(VIEw itemVIEw) {        super(itemVIEw);        profilePicture = (circleimageVIEw) itemVIEw.findVIEwByID(R.ID.profile_circle_image);        eyeIcon = (ImageVIEw) itemVIEw.findVIEwByID(R.ID.icon_circle_image);        backgroundImage = (ImageVIEw) itemVIEw.findVIEwByID(R.ID.thumbnail_image);        reliveDescription = (TextVIEw) itemVIEw.findVIEwByID(R.ID.description_textvIEw);        imageLoading = (Progressbar) itemVIEw.findVIEwByID(R.ID.image_loading);    }}

}

这是我的布局:

activity_channel_details

 <?xml version="1.0" enCoding="utf-8"?><linearLayout      xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"androID:orIEntation="vertical"><androID.support.v7.Widget.Toolbar    androID:ID="@+ID/toolbar_details"    androID:layout_wIDth="match_parent"    androID:layout_height="60dp"    androID:background="#017789"    androID:textAlignment="center">    <TextVIEw        androID:ID="@+ID/txt_toolbar_Title"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_gravity="center"        androID:textcolor="@androID:color/white"        androID:textStyle="bold" />    <ImageVIEw        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_gravity="end"        androID:layout_marginEnd="10dp"        androID:background="@color/white_trans"        androID:src="@drawable/zeality" /></androID.support.v7.Widget.Toolbar><androID.support.v4.Widget.nestedScrollVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:background="#fff"    androID:orIEntation="vertical">    <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:background="#ffff"        androID:orIEntation="vertical">        <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"            androID:layout_wIDth="match_parent"            androID:layout_height="match_parent"            androID:background="#ffff"            androID:orIEntation="vertical">            <relativeLayout                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content">                <ImageVIEw                    androID:ID="@+ID/image_cover_details"                    androID:layout_wIDth="match_parent"                    androID:layout_height="120dp"                    androID:adjustVIEwBounds="true"                    androID:scaleType="fitXY" />                <FrameLayout                    androID:ID="@+ID/frame"                    androID:layout_wIDth="100dp"                    androID:layout_height="110dp"                    androID:layout_centerInParent="true">                    <co.zeality.vrplayer.vIEws.HexagonImageVIEw                        androID:ID="@+ID/img_hex"                        androID:layout_wIDth="wrap_content"                        androID:layout_height="wrap_content"                        androID:layout_alignParenttop="true"                        androID:layout_centerHorizontal="true"                        androID:scaleType="fitXY" />                </FrameLayout>            </relativeLayout>            <relativeLayout                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="5dp">                <androID.support.v7.Widget.RecyclerVIEw                    androID:ID="@+ID/rv_vIDeos"                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:nestedScrollingEnabled="false" />            </relativeLayout>            <androID.support.v7.Widget.RecyclerVIEw                androID:ID="@+ID/rv_relive_details"                androID:layout_wIDth="match_parent"                androID:layout_height="match_parent" />        </linearLayout>    </linearLayout></androID.support.v4.Widget.nestedScrollVIEw>

item_vIDeo_recycle_tile

 <?xml version="1.0" enCoding="utf-8"?><relativeLayout   xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="wrap_content"androID:layout_height="wrap_content"androID:orIEntation="vertical"><ImageVIEw    androID:ID="@+ID/img_thumbnail_background_vIDeo"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:adjustVIEwBounds="true" /><FrameLayout    androID:ID="@+ID/frame_image"    androID:layout_wIDth="150dp"    androID:layout_height="100dp"    androID:layout_centerInParent="true">    <Progressbar        androID:ID="@+ID/pb_vIDeo_loading"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:layout_gravity="center"        androID:foregroundGravity="center"        androID:visibility="gone" />    <ImageVIEw        androID:layout_wIDth="80dp"        androID:layout_height="50dp"        androID:layout_gravity="center_horizontal"        androID:layout_marginBottom="40dp"        androID:src="@drawable/glasses" /></FrameLayout><FrameLayout    androID:layout_wIDth="match_parent"    androID:layout_height="60dp"    androID:layout_alignParentBottom="true"    androID:layout_alignParentStart="true">    <relativeLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content">        <ImageVIEw            androID:ID="@+ID/img_play_button"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_marginBottom="5dp"            androID:layout_marginStart="10dp"            androID:src="@drawable/play_no_circle" />        <TextVIEw            androID:ID="@+ID/txt_vIDeo_name"            androID:layout_wIDth="wrap_content"            androID:layout_marginBottom="5dp"            androID:layout_height="match_parent"            androID:layout_below="@ID/img_play_button"            androID:layout_marginStart="5dp"            androID:textcolor="#FFF" />    </relativeLayout></FrameLayout><VIEw    androID:layout_wIDth="match_parent"    androID:layout_height="5dp"    androID:layout_alignParentBottom="true"    androID:background="#660c7582"></VIEw>

解决方法:

您应使用一个recyclerVIEw(垂直)作为父对象,并在适配器在位置1处绑定视图时,返回一个包含recyclerVIEw(水平)的视图,并为该recyclerVIEw加载其他适配器.请参考图以正确理解.

Main RecyclerVIEw (vertical):       ---------------------------    +   Item 1    ---------------------------    +   Second RecyclerVIEw (Horizontal)    ---------------------------    +   Item 2    ---------------------------

父级RecyclerVIEw适配器代码:

    @OverrIDe        public int getItemVIEwType(int position) {            if (position == 1)                return 0;            else                 return 1;        }    @OverrIDe    public RecyclerVIEw.VIEwHolder onCreateVIEwHolder(VIEwGroup parent, int vIEwType) {        if (vIEwType == 0) {            VIEw v = LayoutInflater.from(context).inflate(R.layout.your_second_recylerVIEw_layout, parent, false);            return new VIEwHolder1(v);        }        else{            VIEw v = LayoutInflater.from(context).inflate(R.layout.your_item_layout, parent, false);            return new VIEwHolder2(v);        }    }

现在,您需要为水平recycleVIEw实现第二个适配器.

总结

以上是内存溢出为你收集整理的android-Vertical RecyclerView内部的Horizo​​ntal RecyclerView全部内容,希望文章能够帮你解决android-Vertical RecyclerView内部的Horizo​​ntal RecyclerView所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存