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

RecyclerView實(shí)現(xiàn)橫向滾動效果

 更新時間:2021年01月02日 09:11:05   作者:" 霎那凝眸,三生不忘゛  
這篇文章主要為大家詳細(xì)介紹了RecyclerView實(shí)現(xiàn)橫向滾動效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了RecyclerView實(shí)現(xiàn)橫向滾動效果的具體代碼,供大家參考,具體內(nèi)容如下

布局文件

<LinearLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".RecyclerViewActivity">
  <androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerView_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="8dp"/>

</LinearLayout>

Item

android:layout_width="100dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="5dp">
<ImageView
    android:id="@+id/iv_recyclerview_imag"
    android:layout_width="wrap_content"
    android:layout_height="100dp" />
 <TextView
    android:id="@+id/tv_recyclerview_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="老虎"
    android:textSize="17sp"
    android:layout_gravity="center"
    android:textStyle="bold"
    android:padding="3dp"/>

</LinearLayout>

適配器

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
  private List<Animal> animalList;
  private int resource;

  public RecyclerViewAdapter(List<Animal> animalList, int resource) {
    this.animalList = animalList;
    this.resource = resource;
  }

  @NonNull
  @Override
  public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext()).inflate(resource,parent,
        false);
    ViewHolder holder = new ViewHolder(itemView);
    return holder;
  }

  @Override
  public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    Animal animal = animalList.get(position);
    holder.animalImag.setImageResource(animal.getImageId());
    holder.animalName.setText(animal.getName());

  }

  @Override
  public int getItemCount() {
    return animalList.size();
  }

  static class ViewHolder extends RecyclerView.ViewHolder{
     ImageView animalImag;
     TextView animalName;
     public ViewHolder(View itemView){
       super(itemView);
       animalImag = itemView.findViewById(R.id.iv_recyclerview_imag);
       animalName = itemView.findViewById(R.id.tv_recyclerview_name);
     }
   }
}

核心代碼

public class RecyclerViewActivity extends AppCompatActivity {
  private List<Animal> animalList = new ArrayList<>();
  private RecyclerView recyclerView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recycler_view);
    recyclerView = findViewById(R.id.recyclerView_view);
    initAnimals();
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    recyclerView.setLayoutManager(linearLayoutManager);
    RecyclerViewAdapter adapter = new RecyclerViewAdapter(animalList,R.layout.recyclerview_item);
    recyclerView.setAdapter(adapter);
  }
  //初始化動物數(shù)據(jù)
  private void initAnimals() {
      Animal daxaing = new Animal("大象", R.drawable.animal_one);
      animalList.add(daxaing);
      Animal shizi = new Animal( "袋鼠", R.drawable.animal_two);
      animalList.add(shizi);
      Animal daishu = new Animal("二哈", R.drawable.animal_three);
      animalList.add(daishu);
      Animal laohu = new Animal("獅子", R.drawable.animal_four);
      animalList.add(laohu);
      Animal zhu = new Animal("豬", R.drawable.animal_five);
      animalList.add(zhu);
      Animal songshu = new Animal("猴子", R.drawable.animal_six);
      animalList.add(songshu);
      Animal baozi = new Animal("豹子", R.drawable.animal_seven);
      animalList.add(baozi);
      Animal shayu = new Animal("鯊魚", R.drawable.animal_eight);
      animalList.add(shayu);
  }

}

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

相關(guān)文章

  • Android實(shí)現(xiàn)獲取SERIAL信息的方法

    Android實(shí)現(xiàn)獲取SERIAL信息的方法

    這篇文章主要介紹了Android實(shí)現(xiàn)獲取SERIAL信息的方法,涉及Android操作SERIAL的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-10-10
  • Android中區(qū)別Drawable Bitmap Canvas Paint

    Android中區(qū)別Drawable Bitmap Canvas Paint

    本文主要介紹Android中Drawable Bitmap Canvas Paint 之間的區(qū)別,這里對這幾個概念做出詳細(xì)介紹,開發(fā)Android游戲的朋友可以參考下
    2016-07-07
  • Android如何在Gradle中更改APK文件名詳解

    Android如何在Gradle中更改APK文件名詳解

    這篇文章主要介紹了Android如何在Gradle中更改APK文件名的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-10-10
  • Android利用animation-list實(shí)現(xiàn)幀動畫

    Android利用animation-list實(shí)現(xiàn)幀動畫

    這篇文章主要為大家詳細(xì)介紹了Android利用animation-list實(shí)現(xiàn)幀動畫,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android viewpage實(shí)現(xiàn)禁止滑動的功能

    Android viewpage實(shí)現(xiàn)禁止滑動的功能

    這篇文章主要介紹了Android viewpage實(shí)現(xiàn)禁止滑動的功能的相關(guān)資料,這里附有實(shí)現(xiàn)的實(shí)例代碼,主要還是重新 ViewPage 這個類,需要的朋友可以參考下
    2016-11-11
  • android 一些工具類匯總

    android 一些工具類匯總

    本文給大家匯總介紹了一些常用的Android工具類,非常的簡單實(shí)用,有需要的小伙伴可以參考下
    2016-08-08
  • Android Handler機(jī)制詳解原理

    Android Handler機(jī)制詳解原理

    Handler主要用于異步消息的處理:當(dāng)發(fā)出一個消息之后,首先進(jìn)入一個消息隊(duì)列,發(fā)送消息的函數(shù)即刻返回,而另外一個部分在消息隊(duì)列中逐一將消息取出,然后對消息進(jìn)行處理,也就是發(fā)送消息和接收消息不是同步的處理。 這種機(jī)制通常用來處理相對耗時比較長的操作
    2021-11-11
  • Android實(shí)現(xiàn)簡易瀏覽器遇到問題的解決方法

    Android實(shí)現(xiàn)簡易瀏覽器遇到問題的解決方法

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡易瀏覽器遇到的一系列問題的解決方法,感興趣的小伙伴們可以參考一下
    2016-06-06
  • android新建草稿刪除后下次開機(jī)還會顯示保存的草稿

    android新建草稿刪除后下次開機(jī)還會顯示保存的草稿

    android 新建一個草稿,保存,然后全部刪除會話,關(guān)機(jī)再開機(jī)后還會顯示保存的草稿,下面與大家分享下具體的解決方法
    2013-06-06
  • 解決Android使用Handler造成內(nèi)存泄露問題

    解決Android使用Handler造成內(nèi)存泄露問題

    內(nèi)存泄露的危害就是會使虛擬機(jī)占用內(nèi)存過高,導(dǎo)致OOM(內(nèi)存溢出),程序出錯。接下來通過本文給大家分享Android使用Handler造成內(nèi)存泄露問題及解決方法,一起看看吧
    2017-08-08

最新評論

贵港市| 中西区| 夹江县| 钟山县| 无极县| 军事| 花垣县| 大邑县| 乌兰浩特市| 靖西县| 浦城县| 东辽县| 西宁市| 红安县| 青神县| 突泉县| 息烽县| 临汾市| 洪湖市| 新津县| 通道| 沙河市| 新泰市| 娄烦县| 吉林市| 双峰县| 花垣县| 建德市| 新巴尔虎左旗| 康乐县| 平阴县| 内丘县| 博乐市| 华宁县| 南澳县| 定日县| 礼泉县| 望城县| 江源县| 塘沽区| 都江堰市|