【UI】时间轴自定义竖直分割线

来源:互联网 发布:eclipse开发java项目 编辑:程序博客网 时间:2024/05/17 06:35

xml布局

<!--时间轴-->  <FrameLayout       android:id="@+id/fl_time_line"       android:layout_width="wrap_content"       android:layout_toRightOf="@id/tv_time_history_erp_detail"           android:layout_marginLeft="8dp"       android:layout_height="match_parent">       <ImageView           android:id="@+id/line_normal_erp_detail"           android:layout_width="wrap_content"           android:layout_height="match_parent"           android:scaleType="fitXY"           android:layout_gravity="center_horizontal"           android:background="@drawable/icon_time_line" />       <ImageView           android:layout_gravity="center_horizontal"           android:id="@+id/iv_point_history_erp_detail"           android:layout_width="9dp"           android:layout_height="9dp"           android:background="@drawable/bg_circle_solid_grey_e0" />   </FrameLayout>

如此布局并不能解决竖直分割线的显示(效果如图)

不能解决竖直分割线的显示

布局文件不能保证竖直分割线的自适应显示,因此需要再代码文件里进行相应的处理

代码如下

ImageView timeLine= (ImageView) historyItemView.findViewById(R.id.line_normal_erp_detail);int height= LayoutUtils.getViewHeight(historyItemView);FrameLayout.LayoutParams params=new FrameLayout.LayoutParams(1, height);timeLine.setLayoutParams(params); 

效果如图,竖直线没有居中。
竖直线没有居中

再添加params.gravity= Gravity.CENTER_HORIZONTAL;
完整代码如下:

ImageView timeLine= (ImageView) historyItemView.findViewById(R.id.line_normal_erp_detail);int height= LayoutUtils.getViewHeight(historyItemView);FrameLayout.LayoutParams params=new FrameLayout.LayoutParams(1, height);params.gravity= Gravity.CENTER_HORIZONTAL;//居中设置timeLine.setLayoutParams(params);

完善后的效果如图
成功显示

0 0
原创粉丝点击