Android之RecyclerView實(shí)現(xiàn)時(shí)光軸效果示例
做項(xiàng)目的過(guò)程中有個(gè)需求需要時(shí)光軸,于是網(wǎng)上找了部分資料 ,寫了個(gè)案例,現(xiàn)在分享給大家。
如圖:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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=".MainActivity"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" android:overScrollMode="never" /> </RelativeLayout>
item.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="8dp" android:paddingRight="8dp" android:paddingTop="8dp"> <TextView android:id="@+id/item_timeline_time" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginRight="8dp" android:layout_marginTop="18dp" android:gravity="center_horizontal" android:padding="4dp" android:textColor="@color/colorAccent" android:textSize="16sp" android:text="2015-06-08\n09:56" /> <RelativeLayout android:id="@+id/item_timeline_icon_layout" android:layout_width="48dp" android:layout_height="48dp" android:layout_marginBottom="4dp" android:layout_marginRight="8dp" android:layout_toRightOf="@id/item_timeline_time"> <com.timelinedemo.CircleImageView android:id="@+id/item_timeline_icon_bg" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@android:color/transparent" app:civ_border_width="4dp" /> <ImageView android:id="@+id/item_timeline_icon" android:layout_width="24dp" android:layout_height="24dp" android:layout_centerInParent="true" android:scaleType="fitCenter" /> </RelativeLayout> <TextView android:id="@+id/item_timeline_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="18dp" android:layout_toRightOf="@id/item_timeline_icon_layout" android:text="今日收入" android:textColor="@color/colorPrimary" android:textSize="15sp" /> <TextView android:id="@+id/item_timeline_money" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/item_timeline_content" android:layout_marginTop="8dp" android:layout_toRightOf="@id/item_timeline_icon_layout" android:text="$ 100" android:textColor="@color/colorPrimary" android:textSize="22sp" /> <View android:id="@+id/item_timeline_view" android:layout_width="2dp" android:layout_height="60dp" android:layout_alignLeft="@id/item_timeline_icon_layout" android:layout_below="@id/item_timeline_icon_layout" android:layout_marginLeft="23dp" android:background="@color/colorAccent" /> </RelativeLayout>
Activity.Java
public class MainActivity extends AppCompatActivity { private RecyclerView recyclerView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initLayout(); } private void initLayout(){ recyclerView= (RecyclerView) findViewById(R.id.recyclerView); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setHasFixedSize(true); recyclerView.setItemAnimator(new DefaultItemAnimator()); initData(); } private void initData(){ List<TimeInfo > list=new ArrayList<>(); for(int i=0;i<15;i++){ list.add(new TimeInfo()); } TimelineAdapter mAdapter = new TimelineAdapter(this, list); recyclerView.setAdapter(mAdapter); } }
添加依賴庫(kù):
compile 'com.android.support:recyclerview-v7:23.0.0'
由于代碼太多,完整代碼未給出,源碼直接下載即可
源碼點(diǎn)擊下載:TimeLineDemo_jb51.rar
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android時(shí)光軸實(shí)現(xiàn)淘寶物流信息瀏覽效果
- Android自定義View實(shí)現(xiàn)垂直時(shí)間軸布局
- Android控件之使用ListView實(shí)現(xiàn)時(shí)間軸效果
- Android自定義view仿淘寶快遞物流信息時(shí)間軸
- 教你3分鐘了解Android 簡(jiǎn)易時(shí)間軸的實(shí)現(xiàn)方法
- Android自定義時(shí)間軸的實(shí)現(xiàn)過(guò)程
- Android實(shí)現(xiàn)列表時(shí)間軸
- Android TimeLine 時(shí)間節(jié)點(diǎn)軸的實(shí)現(xiàn)實(shí)例代碼
- Android實(shí)現(xiàn)快遞物流時(shí)間軸效果
- Android自定義recyclerView實(shí)現(xiàn)時(shí)光軸效果
相關(guān)文章
Android實(shí)現(xiàn)音量調(diào)節(jié)的方法
這篇文章主要介紹了Android實(shí)現(xiàn)音量調(diào)節(jié)的方法,涉及Android頁(yè)面布局及多媒體播放的設(shè)置技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09Android筆記之:深入為從右向左語(yǔ)言定義復(fù)雜字串的詳解
本篇文章是對(duì)Android中為從右向左語(yǔ)言定義復(fù)雜字串進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05Android實(shí)現(xiàn)帶磁性的懸浮窗體效果
這篇文章主要介紹了Android實(shí)現(xiàn)帶磁性的懸浮窗體效果,涉及Android針對(duì)窗體的動(dòng)態(tài)操作相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07打飛機(jī)游戲終極BOSS Android實(shí)戰(zhàn)打飛機(jī)游戲完結(jié)篇
打飛機(jī)游戲終極BOSS,Android實(shí)戰(zhàn)打飛機(jī)游戲完結(jié)篇,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07Android應(yīng)用中使用ListView來(lái)分頁(yè)顯示刷新的內(nèi)容
這篇文章主要介紹了Android應(yīng)用中使用ListView來(lái)分頁(yè)顯示刷新的內(nèi)容的方法,展示了一個(gè)點(diǎn)擊按鈕進(jìn)行刷新的實(shí)例以及下拉刷新分頁(yè)顯示的要點(diǎn)解析,需要的朋友可以參考下2016-04-04Android 監(jiān)聽(tīng)WiFi的開(kāi)關(guān)狀態(tài)實(shí)現(xiàn)代碼
這篇文章主要介紹了Android 監(jiān)聽(tīng)WiFi的開(kāi)關(guān)狀態(tài)實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2017-05-05Android實(shí)現(xiàn)計(jì)時(shí)與倒計(jì)時(shí)的方法匯總
這篇文章主要介紹了Android實(shí)現(xiàn)計(jì)時(shí)與倒計(jì)時(shí)的方法匯總,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-06-06Android AlertDialog實(shí)現(xiàn)分享對(duì)話框/退出對(duì)話框/下載對(duì)話框
這篇文章主要介紹了Android AlertDialog實(shí)現(xiàn)分享對(duì)話框/退出對(duì)話框/下載對(duì)話框的相關(guān)資料,需要的朋友可以參考下2016-04-04