代码之家  ›  专栏  ›  技术社区  ›  Peter234

Android布局weight_sum和mpandroidchart

  •  1
  • Peter234  · 技术社区  · 10 年前

    我正在为自己编写一个小小的Android应用程序。 现在我与体重作斗争。如果我使用下面显示的代码,我的应用程序什么也不显示。但是,如果我使用230dp,它可以完美工作。我在重量上做错了什么。 你能帮我吗?

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipe_refresh_layout_history"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ScrollView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <LinearLayout
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:id="@+id/linearLayoutHistory"
                android:weightSum="100">
                <com.github.mikephil.charting.charts.BarChart
                    android:id="@+id/chart"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_marginTop="@dimen/activity_left_margin"
                    android:layout_weight="50"/>
    
                <com.github.mikephil.charting.charts.BarChart
                    android:id="@+id/weekdayChart"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_marginTop="@dimen/activity_left_margin"
                    android:layout_weight="50"/>
            </LinearLayout>
    
        </ScrollView>
    </android.support.v4.widget.SwipeRefreshLayout>
    
    1 回复  |  直到 10 年前
        1
  •  0
  •   Peter234    10 年前

    我自己找到了答案。但我认为我不是唯一一个面临这个问题的人,所以我在这里回答。。。 这是滚动视图和layout_weight的问题。 只需将滚动视图设置为:android:fillViewport=“true”,它就会工作!

    希望我能帮助别人:)