Android TimeLine 時(shí)間節(jié)點(diǎn)軸的實(shí)現(xiàn)實(shí)例代碼
整理文檔,搜刮出一個(gè)Android TimeLine 時(shí)間節(jié)點(diǎn)軸的實(shí)現(xiàn)實(shí)例代碼,稍微整理精簡(jiǎn)一下做下分享。
效果圖

具體實(shí)現(xiàn) (RecyclerView)
1.Adapter
package com.haoren.timeline;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
/**
* Created by Hh on 2017/3/8.
*/
public class TimeLineAdapter extends RecyclerView.Adapter<TimeLineAdapter.HorizontalVh> {
private Context context;
//時(shí)間節(jié)點(diǎn)數(shù)
private int nodeNum = 0;
//當(dāng)前到達(dá)節(jié)點(diǎn)
private int currentNode = 1;
public TimeLineAdapter(Context context, int nodeNum) {
this.context = context;
this.nodeNum = nodeNum;
}
@Override
public HorizontalVh onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.time_line, null, false);
HorizontalVh vh = new HorizontalVh(view);
return vh;
}
@Override
public void onBindViewHolder(HorizontalVh holder, int position) {
if (position < currentNode) {
//當(dāng)前節(jié)點(diǎn)之前的全部設(shè)為已經(jīng)經(jīng)過(guò)
holder.point.setImageResource(R.mipmap.point_select);
holder.lineLeft.setBackgroundResource(R.color.colorPrimary);
holder.lineRight.setBackgroundResource(R.color.colorPrimary);
}
// 去掉左右兩頭的分支
if (position == 0) {
holder.lineLeft.setVisibility(View.INVISIBLE);
}
if (position == nodeNum - 1) {
holder.lineRight.setVisibility(View.INVISIBLE);
}
}
@Override
public int getItemCount() {
return nodeNum;
}
/**
* 設(shè)置當(dāng)前節(jié)點(diǎn)
* @param currentNode
*/
public void setCurrentNode(int currentNode) {
this.currentNode = currentNode;
this.notifyDataSetChanged();
}
class HorizontalVh extends RecyclerView.ViewHolder {
private ImageView point;
private View lineLeft, lineRight;
public HorizontalVh(View itemView) {
super(itemView);
this.point = (ImageView) itemView.findViewById(R.id.point);
this.lineLeft = itemView.findViewById(R.id.line_left);
this.lineRight = itemView.findViewById(R.id.line_right);
}
}
}
item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="50dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<RelativeLayout
android:layout_marginTop="20dp"
android:layout_width="40dp"
android:layout_height="wrap_content">
<View
android:id="@+id/line_left"
android:layout_width="20dp"
android:layout_height="1dp"
android:layout_centerVertical="true"
android:background="#A6A6A6" />
<View
android:id="@+id/line_right"
android:layout_width="20dp"
android:layout_height="1dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/line_left"
android:background="#A6A6A6" />
<ImageView
android:id="@+id/point"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_centerHorizontal="true"
android:scaleType="center"
android:src="@mipmap/point_normal" />
</RelativeLayout>
<TextView
android:id="@+id/show_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="node"
android:textSize="11sp" />
</LinearLayout>
MainActivity
package com.haoren.timeline;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
public class MainActivity extends AppCompatActivity {
private RecyclerView mRecyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = (RecyclerView) findViewById(R.id.mRecyclerView);
initAdapter();
}
private void initAdapter() {
TimeLineAdapter adapter = new TimeLineAdapter(this, 8);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
mRecyclerView.setAdapter(adapter);
adapter.setCurrentNode(5);
}
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android之RecyclerView實(shí)現(xiàn)時(shí)光軸效果示例
- 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實(shí)現(xiàn)快遞物流時(shí)間軸效果
- Android自定義recyclerView實(shí)現(xiàn)時(shí)光軸效果
相關(guān)文章
Android中兩個(gè)類讓你再也不用實(shí)現(xiàn)onActivityResult()
這篇文章主要給大家介紹了關(guān)于Android中兩個(gè)類讓你再也不用實(shí)現(xiàn)onActivityResult()的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧2018-08-08
Android 實(shí)現(xiàn)滑動(dòng)方法總結(jié)
這篇文章主要介紹了Android 實(shí)現(xiàn)滑動(dòng)方法總結(jié)的相關(guān)資料,需要的朋友可以參考下2017-07-07
Android創(chuàng)建Menu菜單實(shí)例
這篇文章主要介紹了Android創(chuàng)建Menu菜單實(shí)例,講述了Android菜單項(xiàng)的創(chuàng)建方法,在Android應(yīng)用程序開發(fā)中非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-10-10
Android android:exported = true 用法詳解
在本篇文章里小編給大家整理了關(guān)于Android android:exported = true 用法,需要的朋友們參考下。2019-09-09
利用源碼編譯Android系統(tǒng)的APK和可執(zhí)行命令的方法
這篇文章主要介紹了利用源碼編譯Android系統(tǒng)的APK和可執(zhí)行命令的方法,示例在Linux系統(tǒng)環(huán)境上進(jìn)行構(gòu)建,需要的朋友可以參考下2016-02-02
Java4Android開發(fā)教程(五)java的基本數(shù)據(jù)類型特征
這篇文章主要介紹了Java4Android開發(fā)教程的第五篇文章java的基本數(shù)據(jù)類型特征,需要的朋友可以參考下2014-10-10
Android Activity與Intent詳解及示例代碼
本文主要講解Android Activity與Intent的知識(shí),這里整理了相關(guān)資料并附有示例代碼,有興趣的小伙伴可以參考下2016-08-08
ScrollView與ListView合用(正確計(jì)算Listview的高度)的問(wèn)題解決
最近做項(xiàng)目中用到ScrollView和ListView一起使用的問(wèn)題,顯示的時(shí)候ListView不能完全正確的顯示,查了好多資料終于成功解決:2013-05-05

