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 SpannableString多行圖文混排的應(yīng)用實(shí)戰(zhàn)
本篇文章主要介紹了Android SpannableString多行圖文混排的應(yīng)用實(shí)戰(zhàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
Android6.0指紋識(shí)別開(kāi)發(fā)實(shí)例詳解
這篇文章主要介紹了Android6.0指紋識(shí)別開(kāi)發(fā)實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-04-04
Flutter事件監(jiān)聽(tīng)與EventBus事件的應(yīng)用詳解
EventBus的核心是基于Streams。它允許偵聽(tīng)器訂閱事件并允許發(fā)布者觸發(fā)事件,使得不同組件的數(shù)據(jù)不需要一層層傳遞,可以直接通過(guò)EventBus實(shí)現(xiàn)跨組件通訊2023-04-04
Android實(shí)現(xiàn)簡(jiǎn)易登陸注冊(cè)邏輯的實(shí)例代碼
在android的應(yīng)用中越來(lái)越多的包含了網(wǎng)絡(luò)互動(dòng)功能,這就帶來(lái)了注冊(cè),登陸賬號(hào)功能,這篇文章主要給大家介紹了關(guān)于Android實(shí)現(xiàn)簡(jiǎn)易登陸注冊(cè)邏輯的相關(guān)資料,需要的朋友可以參考下2021-06-06
Android編程設(shè)計(jì)模式之迭代器模式詳解
這篇文章主要介紹了Android編程設(shè)計(jì)模式之迭代器模式,結(jié)合實(shí)例形式詳細(xì)分析了Android迭代器模式的概念、原理、應(yīng)用場(chǎng)景、用法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2017-12-12
Android實(shí)現(xiàn)不同apk間共享數(shù)據(jù)的方法(2種方法)
這篇文章主要介紹了Android實(shí)現(xiàn)不同apk間共享數(shù)據(jù)的方法,介紹了apk自定義借口實(shí)現(xiàn)數(shù)據(jù)共享與基于User id的數(shù)據(jù)共享,并重點(diǎn)介紹了基于User id的數(shù)據(jù)共享實(shí)現(xiàn)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2016-01-01
Android 使用AlarmManager和NotificationManager來(lái)實(shí)現(xiàn)鬧鐘和通知欄
這篇文章主要介紹了Android 使用AlarmManager和NotificationManager來(lái)實(shí)現(xiàn)鬧鐘和通知欄,需要的朋友可以參考下2017-02-02

