电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術(shù)文章
文章詳情頁

Android recyclerview實(shí)現(xiàn)縱向虛線時(shí)間軸的示例代碼

瀏覽:6日期:2022-09-17 15:00:53

效果圖

Android recyclerview實(shí)現(xiàn)縱向虛線時(shí)間軸的示例代碼

代碼

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自定義虛線 * @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); }}

<?xml version='1.0' encoding='utf-8'?><LinearLayout 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' android:orientation='vertical' tools:context='.MainActivity'> <androidx.recyclerview.widget.RecyclerViewandroid: android:layout_width='match_parent'android:layout_height='match_parent'android:layout_marginTop='20dp' /> </LinearLayout>

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 2021/7/21 17:38 */public class TimeLineAdapter extends RecyclerView.Adapter<TimeLineAdapter.ViewHolder> { 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()).inflate(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);//第一條數(shù)據(jù)隱藏頭部線holder.line_down.setVisibility(position == 4 ? View.INVISIBLE : View.VISIBLE);//最后一條數(shù)據(jù)隱藏底部線 } @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);} }}

<?xml version='1.0' encoding='utf-8'?><LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' android:layout_width='match_parent' android:layout_height='wrap_content' xmlns:custom='http://schemas.android.com/apk/res-auto' android:orientation='horizontal' android:id='@+id/rl_history_root'> <LinearLayoutandroid:layout_width='10dp'android:layout_height='match_parent'android:gravity='center_horizontal'android:layout_marginLeft='12dp'android:orientation='vertical'> <com.jh.timelinedemo.DividerView android: android:layout_width='1dp' android:layout_height='7dp' android:layerType='software' custom:dashGap='2dp' custom:dashLength='2dp' custom:dashThickness='1dp' custom:divider_line_color='#A3A9BD' custom:divider_orientation='vertical' /> <ImageView android:layout_width='10dp' android:layout_height='10dp' android: android:src='http://www.hdgsjgj.cn/bcjs/@mipmap/ic_rhombus_green' /> <com.jh.timelinedemo.DividerView android: android:layout_width='1dp' android:layout_height='match_parent' android:layerType='software' custom:dashGap='2dp' custom:dashLength='2dp' custom:dashThickness='1dp' custom:divider_line_color='#A3A9BD' custom:divider_orientation='vertical' /> </LinearLayout> <LinearLayoutandroid:layout_width='match_parent'android:layout_height='match_parent'android:layout_marginLeft='19dp'android:orientation='vertical'android:paddingBottom='30dp'> <TextView android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_centerVertical='true' android:text='標(biāo)題 標(biāo)題 標(biāo)題' android:textColor='#2f3856' android:textSize='14sp' /> <TextView android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_centerVertical='true' android:layout_marginTop='6dp' android:text='內(nèi)容 內(nèi)容 ' android:textColor='#2f3856' android:textSize='14sp' /> </LinearLayout></LinearLayout>

<!-- 垂直方向的虛線 --> <declare-styleable name='DividerView'><!-- 虛線顏色 --><attr name='divider_line_color' format='color'/><!-- 虛線寬度 --><attr name='dashThickness' format='dimension'/><!-- 虛線dash寬度 --><attr name='dashLength' format='dimension'/><!-- 虛線dash間隔 --><attr name='dashGap' format='dimension'/><!-- 虛線朝向 --><attr name='divider_orientation' format='enum'> <enum name='horizontal' value='0'/> <enum name='vertical' value='1'/></attr> </declare-styleable>

到此這篇關(guān)于Android recyclerview實(shí)現(xiàn)縱向虛線時(shí)間軸的示例代碼的文章就介紹到這了,更多相關(guān)Android recyclerview縱向虛線時(shí)間軸內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 软文发布平台 - 云软媒网络软文直编发布营销推广平台 | 螺杆式冷水机-低温冷水机厂家-冷冻机-风冷式-水冷式冷水机-上海祝松机械有限公司 | 金属清洗剂,防锈油,切削液,磨削液-青岛朗力防锈材料有限公司 | 水上浮桥-游艇码头-浮动码头-游船码头-码瑞纳游艇码头工程 | 升降机-高空作业车租赁-蜘蛛车-曲臂式伸缩臂剪叉式液压升降平台-脚手架-【普雷斯特公司厂家】 | 喷涂流水线,涂装流水线,喷漆流水线-山东天意设备科技有限公司 | 袋式过滤器,自清洗过滤器,保安过滤器,篮式过滤器,气体过滤器,全自动过滤器,反冲洗过滤器,管道过滤器,无锡驰业环保科技有限公司 | 欧洲MV日韩MV国产_人妻无码一区二区三区免费_少妇被 到高潮喷出白浆av_精品少妇自慰到喷水AV网站 | 便携式XPDM露点仪-在线式防爆露点仪-增强型烟气分析仪-约克仪器 冰雕-冰雪世界-大型冰雕展制作公司-赛北冰雕官网 | CCC验厂-家用电器|服务器CCC认证咨询-奥测世纪| 博客-悦享汽车品质生活 | 真空粉体取样阀,电动楔式闸阀,电动针型阀-耐苛尔(上海)自动化仪表有限公司 | 螺旋丝杆升降机-SWL蜗轮-滚珠丝杆升降机厂家-山东明泰传动机械有限公司 | 合肥角钢_合肥槽钢_安徽镀锌管厂家-昆瑟商贸有限公司 | 济南轻型钢结构/济南铁艺护栏/济南铁艺大门-济南燕翔铁艺制品有限公司 | 游动电流仪-流通式浊度分析仪-杰普仪器(上海)有限公司 | 激光内雕_led玻璃_发光玻璃_内雕玻璃_导光玻璃-石家庄明晨三维科技有限公司 激光内雕-内雕玻璃-发光玻璃 | 密集架|电动密集架|移动密集架|黑龙江档案密集架-大量现货厂家销售 | 红外光谱仪维修_二手红外光谱仪_红外压片机_红外附件-天津博精仪器 | 大型冰雕-景区冰雕展制作公司,3D创意设计源头厂家-[赛北冰雕] | 北京中创汇安科贸有限公司 | 温州中研白癜风专科_温州治疗白癜风_温州治疗白癜风医院哪家好_温州哪里治疗白癜风 | 无锡网站建设_小程序制作_网站设计公司_无锡网络公司_网站制作 | 公交驾校-北京公交驾校欢迎您!| 湖南自考_湖南自学考试 | 泰来华顿液氮罐,美国MVE液氮罐,自增压液氮罐,定制液氮生物容器,进口杜瓦瓶-上海京灿精密机械有限公司 | 轴承振动测量仪电箱-轴承测振动仪器-测试仪厂家-杭州居易电气 | 防勒索软件_数据防泄密_Trellix(原McAfee)核心代理商_Trellix(原Fireeye)售后-广州文智信息科技有限公司 | 河南橡胶接头厂家,河南波纹补偿器厂家,河南可曲挠橡胶软连接,河南套筒补偿器厂家-河南正大阀门 | 液压油缸-液压缸厂家价格,液压站系统-山东国立液压制造有限公司 液压油缸生产厂家-山东液压站-济南捷兴液压机电设备有限公司 | 二手色谱仪器,十万分之一分析天平,蒸发光检测器,电位滴定仪-湖北捷岛科学仪器有限公司 | 定制异形重型钢格栅板/钢格板_定做踏步板/排水沟盖板_钢格栅板批发厂家-河北圣墨金属制品有限公司 | 棉柔巾代加工_洗脸巾oem_一次性毛巾_浴巾生产厂家-杭州禾壹卫品科技有限公司 | 长沙中央空调维修,中央空调清洗维保,空气能热水工程,价格,公司就找维小保-湖南维小保环保科技有限公司 | 温州在线网| 热工多功能信号校验仪-热电阻热电偶校验仿真仪-金湖虹润仪表 | 保定市泰宏机械制造厂-河北铸件厂-铸造厂-铸件加工-河北大件加工 | 琉璃瓦-琉璃瓦厂家-安徽盛阳新型建材科技有限公司 | 精益专家 - 设备管理软件|HSE管理系统|设备管理系统|EHS安全管理系统 | 气力输送_输送机械_自动化配料系统_负压吸送_制造主力军江苏高达智能装备有限公司! | 信阳网站建设专家-信阳时代网联-【信阳网站建设百度推广优质服务提供商】信阳网站建设|信阳网络公司|信阳网络营销推广 |