Sepehr Nozaryian
Sepehr Nozaryian

Reputation: 370

Adding graphview to RelativeLayout in scrollview

I have been working with the GraphView Library. i have to add add the GraphView programmatically.

when i add graph to the RelativeLayout ,if the textview fill the page it won't show the graph.but if the textview was empty or not fill the page completely the graph will show up but not all of it. it won't scroll at all....

i'm trying to add the graph under the textview.

this is my 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>

Code...

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);

i stock in this for days, thanks in advance.

Upvotes: 0

Views: 1356

Answers (2)

Sepehr Nozaryian
Sepehr Nozaryian

Reputation: 370

I accidently found how to make it work. if i add a textview programmatically after a graphview it work fine. by the way i have to set a text for 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>

Code:

 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);

(I dont know why it happen and now it work...)

Upvotes: 1

Ravi Bhayani
Ravi Bhayani

Reputation: 151

Make android:orientation="vertical" as you want GraphView below the textview. And use LinearLayout instead of RelativeLayout.

If you want to use RelativeLayout then LayoutParams of RelativeLayout should be MATCH_PARENT instead if WRAP_CONTENT and the gravity of TextView and GraphView should be "top" and "bottom" respectively.

Hope it will help

Upvotes: 1

Related Questions