0

我一直在使用 GraphView 库。我必须以编程方式添加添加 GraphView。

当我将图形添加到 RelativeLayout 时,如果 textview 填充页面,它将不会显示图形。但如果 textview 为空或未完全填充页面,图形将显示但不是全部。它根本不会滚动....

我正在尝试在 textview 下添加图形。

这是我的xml

  <ScrollView
        android:id="@+id/ScrollView02"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        android:scrollbars="none" >

        <RelativeLayout
            android:id="@+id/reletive_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
        <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"/>
    </RelativeLayout>
    </ScrollView>

代码...

GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
                new GraphViewData(1, 2.0d)
                , new GraphViewData(2, 1.5d)
                , new GraphViewData(3, 2.5d)
                , new GraphViewData(4, 1.0d)
            });

            GraphView graphView = new LineGraphView(getActivity(), "GraphViewDemo");
            graphView.addSeries(exampleSeries); // data
            RelativeLayout layout = (RelativeLayout) v.findViewById(R.id.reletive_layout);
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            params.addRule(RelativeLayout.BELOW, tv2.getId());
            layout.addView(graphView,params);

我存了几天,提前谢谢。

4

2 回答 2

1

将 android:orientation="vertical" 设置为文本视图下方的 GraphView。并使用 LinearLayout 而不是 RelativeLayout。

如果你想使用RelativeLayout,那么RelativeLayout 的LayoutParams 应该是MATCH_PARENT,而不是WRAP_CONTENT 并且TextView 和GraphView 的重力应该分别是“top”和“bottom”。

希望它会有所帮助

于 2014-07-11T06:05:34.103 回答
1

我偶然发现了如何使它工作。如果我在graphview之后以编程方式添加一个textview,它工作正常。顺便说一句,我必须为 textview 设置一个文本。

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="30dp" />

    <LinearLayout
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </LinearLayout>
</LinearLayout>

代码:

 GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
            new GraphViewData(1, 2.0d)
            , new GraphViewData(2, 1.5d)
            , new GraphViewData(3, 2.5d)
            , new GraphViewData(4, 1.0d)
        });

        final GraphView graphView = new LineGraphView(
            this // context
            , "GraphViewDemo" // heading
        );
        graphView.addSeries(exampleSeries); // data

        LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
        layout.addView(graphView);

        TextView tv3=new TextView(getApplicationContext());
        tv3.setText("                ");
        layout.addView(tv3);

(我不知道它为什么会发生,现在它起作用了......)

于 2014-07-16T07:22:58.227 回答