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

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

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

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

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);
  //設置布局管理器
  LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
  linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
  recyclerview_horizontal1.setLayoutManager(linearLayoutManager);
  //設置適配器
  mAdapter1 = new GalleryAdapter(this, mDatas1);
  recyclerview_horizontal1.setAdapter(mAdapter1);
 
  //得到控件
  recyclerview_horizontal2 = (RecyclerView)findViewById(R.id.recyclerview_horizontal2);
  //設置布局管理器
  LinearLayoutManager linearLayoutManager2 = new LinearLayoutManager(this);
  linearLayoutManager2.setOrientation(LinearLayoutManager.HORIZONTAL);
  recyclerview_horizontal2.setLayoutManager(linearLayoutManager2);
  //設置適配器
  mAdapter2 = new GalleryAdapter(this, mDatas2);
  recyclerview_horizontal2.setAdapter(mAdapter2);
 
  //得到控件
  recyclerview_horizontal3 = (RecyclerView)findViewById(R.id.recyclerview_horizontal3);
  //設置布局管理器
  LinearLayoutManager linearLayoutManager3 = new LinearLayoutManager(this);
  linearLayoutManager3.setOrientation(LinearLayoutManager.HORIZONTAL);
  recyclerview_horizontal3.setLayoutManager(linearLayoutManager3);
  //設置適配器
  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;
  }
  /**
   * 設置值
   */
  @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);
  //設置布局管理器
  LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
  linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
  recyclerview_horizontal1.setLayoutManager(linearLayoutManager);
  //設置適配器
  mAdapter1 = new GalleryAdapter(this, mDatas1);
  recyclerview_horizontal1.setAdapter(mAdapter1);

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

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

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

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

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

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

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

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

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

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

    詳解如何魔改Retrofit實例

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

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

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

    Android ADB簡介、安裝及使用詳解

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

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

    對圖片本身進行操作。盡量不要使用setImageBitmap、setImageResource、BitmapFactory.decodeResource來設置一張大圖,因為這些方法在完成decode后,最終都是通過java層的createBitmap來完成的,需要消耗更多內存
    2012-12-12
  • Android使用google breakpad捕獲分析native cash

    Android使用google breakpad捕獲分析native cash

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

    詳解Android TableLayout表格布局

    表格布局的標簽是TableLayout,TableLayout繼承了LinearLayout。所以它依然是一個線性布局,通過本文給大家介紹Android TableLayout表格布局,感興趣的朋友一起學習吧
    2016-02-02

最新評論

安丘市| 东明县| 黄龙县| 紫云| 东城区| 鲁甸县| 吉木乃县| 凌海市| 通海县| 台前县| 巴林右旗| 八宿县| 章丘市| 壶关县| 石棉县| 虹口区| 平塘县| 滦平县| 黎川县| 拉孜县| 宣化县| 乌拉特前旗| 肇州县| 五指山市| 高雄县| 莲花县| 望城县| 合山市| 昌都县| 曲水县| 桑日县| 汉中市| 琼结县| 呈贡县| 平武县| 都江堰市| 水富县| 新龙县| 赫章县| 社旗县| 周口市|