In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "how to use Android recyclerview to achieve the vertical dotted timeline", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to use Android recyclerview to achieve the vertical dotted timeline"!
Effect picture
Code
Package com.jh.timelinedemo; import android.content.Context;import android.content.res.TypedArray;import android.graphics.Canvas;import android.graphics.DashPathEffect;import android.graphics.Paint;import android.util.AttributeSet;import android.view.View; / * * @ Description: Android custom dashed line * @ Date 2019-07-20 10:07 * @ Version * / public class DividerView extends View {static public int ORIENTATION_HORIZONTAL = 0; static public int ORIENTATION_VERTICAL = 1; private Paint mPaint Private int orientation; public DividerView (Context context) {this (context, null);} public DividerView (Context context, AttributeSet attrs) {super (context, attrs); int dashGap, dashLength, dashThickness; int color; TypedArray a = context.getTheme (). ObtainStyledAttributes (attrs, R.styleable.DividerView, 0,0); try {dashGap = a.getDimensionPixelSize (R.styleable.DividerView_dashGap, 5) DashLength = a.getDimensionPixelSize (R.styleable.DividerView_dashLength, 5); dashThickness = a.getDimensionPixelSize (R.styleable.DividerView_dashThickness, 3); color = a.getColor (R.styleable.DividerView_divider_line_color, 0xff000000); orientation = a.getInt (R.styleable.DividerView_divider_orientation, ORIENTATION_HORIZONTAL);} finally {a.recycle () } mPaint = new Paint (); mPaint.setAntiAlias (true); mPaint.setColor (color); mPaint.setStyle (Paint.Style.STROKE); mPaint.setStrokeWidth (dashThickness); mPaint.setPathEffect (new DashPathEffect (new float [] {dashGap, dashLength,}, 0)); public void setBgColor (int color) {mPaint.setColor (color); invalidate () } @ Override protected void onDraw (Canvas canvas) {if (orientation = = ORIENTATION_HORIZONTAL) {float center = getHeight () * 0.5f; canvas.drawLine (0, center, getWidth (), center, mPaint);} else {float center = getWidth () * 0.5f; canvas.drawLine (center, 0, center, getHeight (), mPaint) } package com.jh.timelinedemo; import androidx.appcompat.app.AppCompatActivity;import androidx.recyclerview.widget.LinearLayoutManager;import androidx.recyclerview.widget.RecyclerView; import android.os.Bundle;import android.view.View; public class MainActivity extends AppCompatActivity {private RecyclerView rcy; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); rcy = findViewById (R.id.rcy) LinearLayoutManager manager = new LinearLayoutManager (this, RecyclerView.VERTICAL, false); rcy.setLayoutManager (manager); TimeLineAdapter adapter = new TimeLineAdapter (this); rcy.setAdapter (adapter);}} package com.jh.timelinedemo; import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup; import androidx.annotation.NonNull;import androidx.recyclerview.widget.RecyclerView / * @ date:on 17:38 on 2021-7-21 * / public class TimeLineAdapter extends RecyclerView.Adapter {private Context context; public TimeLineAdapter (Context context) {this.context = context;} @ NonNull @ Override public TimeLineAdapter.ViewHolder onCreateViewHolder (@ NonNull ViewGroup parent, int viewType) {View inflate = LayoutInflater.from (parent.getContext ()) .propagate (R.layout.item_layout, null); ViewHolder viewHolder = new ViewHolder (inflate) Return viewHolder;} @ Override public void onBindViewHolder (@ NonNull TimeLineAdapter.ViewHolder holder, int position) {holder.line_up.setVisibility (position = = 0? View.INVISIBLE: View.VISIBLE); / / the first data hidden header line holder.line_down.setVisibility (position = = 4? View.INVISIBLE: View.VISIBLE); / / Last data hiding bottom line} @ Override public int getItemCount () {return 5;} class ViewHolder extends RecyclerView.ViewHolder {private final DividerView line_up, line_down; public ViewHolder (@ NonNull View itemView) {super (itemView); line_up = itemView.findViewById (R.id.line_up) Line_down = itemView.findViewById (R.id.line_down) } so far I believe you have a deeper understanding of "how to use Android recyclerview to achieve the vertical dotted timeline". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.