功能是这样的,一个 HorizontalScrollView,里面装了一个自定义的图表DrawChartsView,图表可以左右滑动查看内容
XML文件
<! - 设置图表可以横向滑动 - > < HorizontalScrollView android :layout_width = “match_parent” android :layout_height = “wrap_content” android :id = “@ + id / scrollView” >
< LinearLayout android :layout_width = “match_parent” android :layout_height = “wrap_content” android :orientation = “horizontal” android :gravity = “center” >
<! - 自定义图表视图 - >
<com.kingserry.charts.DrawChartsView
android:layout_marginStart =“5dp”
android:layout_marginTop =“10dp”
android:id =“@ + id / drawView”
android:layout_width =“550dp”
android:layout_height =“250dp”
android:background =“#ffe0e0e0”
app:XYColor =“#ff404040”
app:XTextColor =“#ff202020”
app:YTextColor =“#ff2020e0”
app:pointColor =“#FFFF0000”
app:lineColor =“#ff20e090”
app:XYMargin = “30dp” />
</ LinearLayout >
</ HorizontalScrollView >
程序还可以控制需要滑动到的位置
//横向滚动到图表的最右端java代码 HorizontalScrollView scrollView = findViewById( R.id.scrollView); scrollView.scrollTo(drawChartsView.getRight(),0);