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

Android RecyclerView 實(shí)現(xiàn)快速滾動(dòng)的示例代碼

 更新時(shí)間:2017年09月09日 15:28:09   作者:Hevin  
本篇文章主要介紹了Android RecyclerView 實(shí)現(xiàn)快速滾動(dòng)的示例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下

簡評:Android Support Library 26 中終于實(shí)現(xiàn)了一個(gè)等待已久的功能: RecyclerView 的快速滾動(dòng) 。

Android 官方早就在建議開發(fā)者使用 RecyclerView 替代 ListView,RecyclerView 也確實(shí)表現(xiàn)要好于 ListView,除了沒有快速滾動(dòng),就像下面這樣:

因此,之前要想在 RecyclerView 上實(shí)現(xiàn)快速滾動(dòng),往往是依賴第三方庫,比如:FutureMind/recycler-fast-scroll timusus/RecyclerView-FastScroll 。

現(xiàn)在 RecyclerView 終于原生支持了快速滾動(dòng),現(xiàn)在就讓我們來看一下怎么實(shí)現(xiàn):

首先,在 build.gradle 中添加依賴:

dependencies {
  ....
  compile 'com.android.support:design:26.0.2'
  compile 'com.android.support:recyclerview-v7:26.0.2'
  ....
}

注意 Support Library 從版本 26 開始移到了 Google 的 maven 倉庫,并且 Google 計(jì)劃未來將所有的倉庫都只通過 http:// maven.google.com 來發(fā)布。所以,需要參考 官方指南 使用 Google Maven 倉庫。

現(xiàn)在,來看一看具體怎么實(shí)現(xiàn) RecyclerView 的快速滾動(dòng):

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  app:layout_behavior="@string/appbar_scrolling_view_behavior"
  tools:context="com.shaishavgandhi.fastscrolling.MainActivity"
  tools:showIn="@layout/activity_main">


 <android.support.v7.widget.RecyclerView
  android:id="@+id/recyclerView"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  app:fastScrollEnabled="true"
  app:fastScrollHorizontalThumbDrawable="@drawable/thumb_drawable"
  app:fastScrollHorizontalTrackDrawable="@drawable/line_drawable"
  app:fastScrollVerticalThumbDrawable="@drawable/thumb_drawable"
  app:fastScrollVerticalTrackDrawable="@drawable/line_drawable">

 </android.support.v7.widget.RecyclerView>

</android.support.constraint.ConstraintLayout>

其中增加了幾個(gè)屬性:

  • fastScrollEnabled: boolean 類型,決定是否啟用快速滾動(dòng),當(dāng)設(shè)置為 true 時(shí)需要設(shè)置下面的四個(gè)屬性。
  • fastScrollHorizontalThumbDrawable: 水平滾動(dòng)塊。
  • fastScrollHorizontalTrackDrawable: 水平滾動(dòng)欄背景。
  • fastScrollVerticalThumbDrawable: 豎直滾動(dòng)塊。
  • fastScrollVerticalTrackDrawable: 豎直滾動(dòng)欄背景。

接下來看一下具體的 drawable:

line_drawable.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item
    android:state_pressed="true"
    android:drawable="@drawable/line"/>

  <item
    android:drawable="@drawable/line"/>
</selector>

line.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

  <solid android:color="@android:color/darker_gray" />

  <padding
    android:top="10dp"
    android:left="10dp"
    android:right="10dp"
    android:bottom="10dp"/>
</shape>

thumb_drawable.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item
    android:state_pressed="true"
    android:drawable="@drawable/thumb"/>

  <item
    android:drawable="@drawable/thumb"/>
</selector>

thumb.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

  <corners
    android:topLeftRadius="44dp"
    android:topRightRadius="44dp"
    android:bottomLeftRadius="44dp" />

  <padding
    android:paddingLeft="22dp"
    android:paddingRight="22dp" />

  <solid android:color="@color/colorPrimaryDark" />

</shape>

效果如下:

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

相關(guān)文章

  • Android回調(diào)與觀察者模式的實(shí)現(xiàn)原理

    Android回調(diào)與觀察者模式的實(shí)現(xiàn)原理

    這篇文章主要為大家詳細(xì)介紹了Android回調(diào)與觀察者模式的實(shí)現(xiàn)原理,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Android自定義View實(shí)現(xiàn)繪制虛線的方法詳解

    Android自定義View實(shí)現(xiàn)繪制虛線的方法詳解

    這篇文章主要給大家介紹了Android自定義View實(shí)現(xiàn)繪制虛線的方法,在繪制過程中走了一些彎路才實(shí)現(xiàn)了虛線的效果,所以想著總結(jié)分享出來,方便有需要的朋友和自己在需要的時(shí)候參考學(xué)習(xí),下面來一起看看吧。
    2017-04-04
  • Android實(shí)現(xiàn)加法計(jì)算器

    Android實(shí)現(xiàn)加法計(jì)算器

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)加法計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • 學(xué)習(xí)理解Android菜單Menu操作

    學(xué)習(xí)理解Android菜單Menu操作

    這篇文章主要幫助大家理解Android菜單Menu操作,引入Android菜單Menu操作的知識(shí),感興趣的小伙伴們可以參考一下
    2016-04-04
  • Android程序開發(fā)仿新版QQ鎖屏下彈窗功能

    Android程序開發(fā)仿新版QQ鎖屏下彈窗功能

    最近做了一個(gè)項(xiàng)目,其中涉及到這樣一個(gè)功能:新版的qq能在鎖屏下彈窗顯示qq消息,下面小編抽時(shí)間把實(shí)現(xiàn)代碼分享給大家感興趣的朋友參考下吧
    2016-09-09
  • Android百度地圖應(yīng)用之創(chuàng)建顯示地圖

    Android百度地圖應(yīng)用之創(chuàng)建顯示地圖

    這篇文章主要為大家詳細(xì)介紹了Android百度地圖應(yīng)用之創(chuàng)建顯示地圖,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-06-06
  • Android拍照上傳功能示例代碼

    Android拍照上傳功能示例代碼

    這篇文章主要介紹了Android拍照上傳功能用法,結(jié)合實(shí)例形式詳細(xì)分析了Android拍照上傳功能所涉及的相關(guān)知識(shí)點(diǎn)與功能實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-08-08
  • Android中FTP上傳、下載的功能實(shí)現(xiàn)(含進(jìn)度)

    Android中FTP上傳、下載的功能實(shí)現(xiàn)(含進(jìn)度)

    本篇文章主要介紹了Android中FTP上傳、下載(含進(jìn)度),具有一定的參考價(jià)值,有需要的可以了解一下。
    2016-11-11
  • Android酷炫動(dòng)畫效果之3D星體旋轉(zhuǎn)效果

    Android酷炫動(dòng)畫效果之3D星體旋轉(zhuǎn)效果

    本文要實(shí)現(xiàn)的3D星體旋轉(zhuǎn)效果是從CoverFlow演繹而來,不過CoverFlow只是對圖像進(jìn)行轉(zhuǎn)動(dòng),我這里要實(shí)現(xiàn)的效果是要對所有的View進(jìn)行類似旋轉(zhuǎn)木馬的轉(zhuǎn)動(dòng)
    2018-05-05
  • Android中捕捉menu按鍵點(diǎn)擊事件的方法

    Android中捕捉menu按鍵點(diǎn)擊事件的方法

    這篇文章主要介紹了Android中捕捉menu按鍵點(diǎn)擊事件的方法,涉及Android響應(yīng)menu菜單項(xiàng)點(diǎn)擊事件的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-07-07

最新評論

柏乡县| 罗城| 大足县| 正阳县| 汤原县| 新田县| 康马县| 玛多县| 宽城| 丰县| 综艺| 洛隆县| 五峰| 南开区| 临沧市| 东明县| 来凤县| 东莞市| 紫金县| 荔浦县| 凌海市| 陇川县| 柘荣县| 康乐县| 班玛县| 宜都市| 泰州市| 会泽县| 肃宁县| 常德市| 长兴县| 察雅县| 包头市| 兴海县| 阜宁县| 松滋市| 合江县| 德令哈市| 进贤县| 内黄县| 延庆县|