最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用RecyclerView實(shí)現(xiàn)水平列表

 更新時(shí)間:2019年09月20日 09:51:22   作者:zhifanxu  
這篇文章主要為大家詳細(xì)介紹了使用RecyclerView實(shí)現(xiàn)水平列表,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了RecyclerView實(shí)現(xiàn)水平列表的具體代碼,供大家參考,具體內(nèi)容如下

1、效果圖

2、activity_horizontallistview.xml

<?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.RecyclerView
  android:id="@+id/recyclerview_horizontal1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal"
  android:overScrollMode="never"
  android:scrollbars="none"
  />
 
 <android.support.v7.widget.RecyclerView
  android:id="@+id/recyclerview_horizontal2"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal"
  android:overScrollMode="never"
  android:scrollbars="none"
  />
 
 <android.support.v7.widget.RecyclerView
  android:id="@+id/recyclerview_horizontal3"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal"
  android:overScrollMode="never"
  android:scrollbars="none"
  />
</LinearLayout>

3、activity代碼

package ivan.com.appbackendtest;
 
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
/**
 * Created by ivan on 2017/6/9.
 */
 
public class HorizontalListviewActivity extends AppCompatActivity {
 private RecyclerView recyclerview_horizontal1;
 private GalleryAdapter mAdapter1;
 private RecyclerView recyclerview_horizontal2;
 private GalleryAdapter mAdapter2;
 private RecyclerView recyclerview_horizontal3;
 private GalleryAdapter mAdapter3;
 private List<Integer> mDatas1;
 private List<Integer> mDatas2;
 private List<Integer> mDatas3;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_horizontallistview);
  initDatas();
  //得到控件
  recyclerview_horizontal1 = (RecyclerView)findViewById(R.id.recyclerview_horizontal1);
  //設(shè)置布局管理器
  LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
  linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
  recyclerview_horizontal1.setLayoutManager(linearLayoutManager);
  //設(shè)置適配器
  mAdapter1 = new GalleryAdapter(this, mDatas1);
  recyclerview_horizontal1.setAdapter(mAdapter1);
 
  //得到控件
  recyclerview_horizontal2 = (RecyclerView)findViewById(R.id.recyclerview_horizontal2);
  //設(shè)置布局管理器
  LinearLayoutManager linearLayoutManager2 = new LinearLayoutManager(this);
  linearLayoutManager2.setOrientation(LinearLayoutManager.HORIZONTAL);
  recyclerview_horizontal2.setLayoutManager(linearLayoutManager2);
  //設(shè)置適配器
  mAdapter2 = new GalleryAdapter(this, mDatas2);
  recyclerview_horizontal2.setAdapter(mAdapter2);
 
  //得到控件
  recyclerview_horizontal3 = (RecyclerView)findViewById(R.id.recyclerview_horizontal3);
  //設(shè)置布局管理器
  LinearLayoutManager linearLayoutManager3 = new LinearLayoutManager(this);
  linearLayoutManager3.setOrientation(LinearLayoutManager.HORIZONTAL);
  recyclerview_horizontal3.setLayoutManager(linearLayoutManager3);
  //設(shè)置適配器
  mAdapter3 = new GalleryAdapter(this, mDatas3);
  recyclerview_horizontal3.setAdapter(mAdapter3);
 }
 private void initDatas()
 {
  mDatas1 = new ArrayList<>(Arrays.asList(R.mipmap.ic_launcher));
  mDatas2 = new ArrayList<>(Arrays.asList(R.mipmap.ic_launcher,R.mipmap.ic_launcher));
  mDatas3 = new ArrayList<>(Arrays.asList(R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher));
 }
 public class GalleryAdapter extends
   RecyclerView.Adapter<GalleryAdapter.ViewHolder>
 {
  private LayoutInflater mInflater;
  private List<Integer> mDatas;
 
  public GalleryAdapter(Context context, List<Integer> datats)
  {
   mInflater = LayoutInflater.from(context);
   mDatas = datats;
  }
 
  public class ViewHolder extends RecyclerView.ViewHolder
  {
   public ViewHolder(View arg0)
   {
    super(arg0);
   }
 
   ImageView mImg;
   TextView mTxt;
  }
 
  @Override
  public int getItemCount()
  {
   return mDatas.size();
  }
 
  /**
   * 創(chuàng)建ViewHolder
   */
  @Override
  public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i)
  {
   View view = mInflater.inflate(R.layout.item_listview,
     viewGroup, false);
   ViewHolder viewHolder = new ViewHolder(view);
 
   viewHolder.mImg = (ImageView) view
     .findViewById(R.id.id_index_gallery_item_image);
   return viewHolder;
  }
  /**
   * 設(shè)置值
   */
  @Override
  public void onBindViewHolder(final ViewHolder viewHolder, final int i)
  {
   viewHolder.mImg.setImageResource(mDatas.get(i));
  }
 }
}

4、核心代碼

 //得到控件
  recyclerview_horizontal1 = (RecyclerView)findViewById(R.id.recyclerview_horizontal1);
  //設(shè)置布局管理器
  LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
  linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
  recyclerview_horizontal1.setLayoutManager(linearLayoutManager);
  //設(shè)置適配器
  mAdapter1 = new GalleryAdapter(this, mDatas1);
  recyclerview_horizontal1.setAdapter(mAdapter1);

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android實(shí)現(xiàn)基于滑動(dòng)的SQLite數(shù)據(jù)分頁(yè)加載技術(shù)(附demo源碼下載)

    Android實(shí)現(xiàn)基于滑動(dòng)的SQLite數(shù)據(jù)分頁(yè)加載技術(shù)(附demo源碼下載)

    這篇文章主要介紹了Android實(shí)現(xiàn)基于滑動(dòng)的SQLite數(shù)據(jù)分頁(yè)加載技術(shù),涉及Android針對(duì)SQLite數(shù)據(jù)的讀取及查詢結(jié)果的分頁(yè)顯示功能相關(guān)實(shí)現(xiàn)技巧,末尾還附帶demo源碼供讀者下載參考,需要的朋友可以參考下
    2016-07-07
  • Android系列---JSON數(shù)據(jù)解析的實(shí)例

    Android系列---JSON數(shù)據(jù)解析的實(shí)例

    JSON(JavaScript Object Notation)和XML,并稱(chēng)為客戶端和服務(wù)端交互解決方案的倚天劍和屠龍刀,這篇文章主要介紹了Android系列---JSON數(shù)據(jù)解析的實(shí)例,有興趣的可以了解一下。
    2016-11-11
  • Android 開(kāi)發(fā)音頻組件(Vitamio FAQ)詳細(xì)介紹

    Android 開(kāi)發(fā)音頻組件(Vitamio FAQ)詳細(xì)介紹

    本文主要介紹Android開(kāi)發(fā)音頻播放器,Vitamio是Android播放器組件,支持幾乎所有視頻格式和網(wǎng)絡(luò)視頻流,希望能幫助開(kāi)發(fā)Android 音頻播放的小伙伴
    2016-07-07
  • Android圖片處理實(shí)例介紹(圖)

    Android圖片處理實(shí)例介紹(圖)

    本篇文章介紹了,Android中圖片處理實(shí)例介紹,需要的朋友參考下
    2013-04-04
  • 詳解如何魔改Retrofit實(shí)例

    詳解如何魔改Retrofit實(shí)例

    這篇文章主要為大家介紹了詳解如何魔改Retrofit實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • 如何在Android中實(shí)現(xiàn)左右滑動(dòng)的指引效果

    如何在Android中實(shí)現(xiàn)左右滑動(dòng)的指引效果

    本篇文章是對(duì)在Android中實(shí)現(xiàn)左右滑動(dòng)指引效果的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • Android ADB簡(jiǎn)介、安裝及使用詳解

    Android ADB簡(jiǎn)介、安裝及使用詳解

    ADB 全稱(chēng)為 Android Debug Bridge,起到調(diào)試橋的作用,是一個(gè)客戶端-服務(wù)器端程序,其中客戶端是用來(lái)操作的電腦,服務(wù)端是 Android 設(shè)備,這篇文章介紹Android ADB簡(jiǎn)介、安裝及使用,感興趣的朋友跟隨小編一起看看吧
    2024-01-01
  • android內(nèi)存優(yōu)化之圖片優(yōu)化

    android內(nèi)存優(yōu)化之圖片優(yōu)化

    對(duì)圖片本身進(jìn)行操作。盡量不要使用setImageBitmap、setImageResource、BitmapFactory.decodeResource來(lái)設(shè)置一張大圖,因?yàn)檫@些方法在完成decode后,最終都是通過(guò)java層的createBitmap來(lái)完成的,需要消耗更多內(nèi)存
    2012-12-12
  • Android使用google breakpad捕獲分析native cash

    Android使用google breakpad捕獲分析native cash

    這篇文章主要介紹了Android使用google breakpad捕獲分析native cash 的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-04-04
  • 詳解Android TableLayout表格布局

    詳解Android TableLayout表格布局

    表格布局的標(biāo)簽是TableLayout,TableLayout繼承了LinearLayout。所以它依然是一個(gè)線性布局,通過(guò)本文給大家介紹Android TableLayout表格布局,感興趣的朋友一起學(xué)習(xí)吧
    2016-02-02

最新評(píng)論

海南省| 康乐县| 略阳县| 孝昌县| 白玉县| 精河县| 高阳县| 静乐县| 郸城县| 吉首市| 雷州市| 神农架林区| 周宁县| 上蔡县| 繁昌县| 罗山县| 漳浦县| 孝昌县| 淮南市| 怀柔区| 兴仁县| 澄江县| 长顺县| 翁源县| 绥芬河市| 神农架林区| 巩义市| 文成县| 巴彦淖尔市| 浏阳市| 孝义市| 雅安市| 射阳县| 嘉义县| 河南省| 库车县| 名山县| 进贤县| 安龙县| 河池市| 西乌珠穆沁旗|