Skip to content

Commit

Permalink
回调一屏显示几个
Browse files Browse the repository at this point in the history
  • Loading branch information
fanhl committed Jun 29, 2018
1 parent 31556fd commit cc589a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions library/src/main/java/com/fanhl/flamebarchart/TravelChart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ class TravelChart @JvmOverloads constructor(
*/
private var resetAnimator: ValueAnimator? = null

/** 在屏幕中最多可以同时显示多少条柱 */
var maxVisibleCount: Int = -1
private set

init {
val configuration = ViewConfiguration.get(context)
mTouchSlop = configuration.scaledTouchSlop
Expand Down Expand Up @@ -570,6 +574,8 @@ class TravelChart @JvmOverloads constructor(
val validWidth = width - paddingLeft - paddingRight
val validHeight = height - paddingTop - paddingBottom

maxVisibleCount = (validWidth + barInterval) / (barWidth + barInterval)

val saveCount = canvas.save()
canvas.translate(paddingLeft.toFloat(), paddingRight.toFloat())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MainActivity : AppCompatActivity() {
chart_travel.data = TravelChart.DefaultData<Item>().apply {
(1..20).forEach { list.add(Item(it, random.nextFloat().takeIf { it > 0.2f })) }
}
tv_max_visible_count.text = "在屏幕中最多可以同时显示多少条柱:\n${chart_travel.maxVisibleCount}"
}

companion object {
Expand Down
14 changes: 14 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,18 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@mipmap/ic_launcher_round"/>

<TextView
android:id="@+id/tv_max_visible_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view_1"/>
</android.support.constraint.ConstraintLayout>

0 comments on commit cc589a1

Please sign in to comment.