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>
w12240cn 回答:MPAndroid Linechart wrap-content 不起作用

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/24079.html

大家都在问