微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MPAndroid Linechart wrap-content 不起作用

如何解决MPAndroid Linechart wrap-content 不起作用

我使用的是 MPAndroid 库中的 Linechart,但我的图表大小几乎没有问题。 我想在卡片视图中显示我的折线图,但我被迫为折线图宽度设置固定大小,因为“wrap-content”和“match-parent”似乎无法根据数据扩展图表宽度数字。 我不知道是我做错了什么,还是 MPAndroid 不允许我这样做,所以如果您有任何想法,请告诉我!谢谢

这是我的 xml 示例和显示它如何在我的应用程序中显示的屏幕截图:

How it appears in app

  <horizontalscrollview
            android:id="@+id/graphScrollView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_margin="10dp"
            android:fillViewport="false">

            <com.google.android.material.card.MaterialCardView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                app:cardCornerRadius="10dp"
                app:cardUseCompatPadding="true">


                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:foregroundGravity="center_horizontal">

                    <TextView
                        android:id="@+id/accountGraphTitle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:layout_marginEnd="16dp"
                        android:gravity="end"
                        android:text="@string/account_chronology_score_title"
                        android:textColor="@color/medium_grey"
                        android:textSize="16sp"
                        android:visibility="gone"
                        app:layout_constraintEnd_toEndOf="@id/graphLayout"
                        app:layout_constraintTop_toTopOf="parent" />

                    <LinearLayout
                        android:id="@+id/graphLayout"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent">

                        <com.github.mikephil.charting.charts.LineChart
                            android:id="@+id/graphView"
                            android:layout_width="wrap_content"
                            android:layout_height="300dp"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintTop_toBottomOf="@id/accountGraphTitle"
                            tools:layout_width="300dp" />

                    </LinearLayout>

                </androidx.constraintlayout.widget.ConstraintLayout>

            </com.google.android.material.card.MaterialCardView>


        </horizontalscrollview>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。