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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...