Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inflate another view into LinearLayout?

This is my XML with 2 LinearLayouts.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
    <LinearLayout
            android:id="@+id/ll_one"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />
    <LinearLayout
            android:id="@+id/ll_two"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />
</LinearLayout>

I have downloaded GraphView from http://android.arnodenhond.com/components/graphview. This class extends View. I basically want to initialize 2 graphs via

String[] verlabels = new String[]{"aim", "25%", "50%", "75%", "start"};
String[] horlabels = new String[]{"this", "max"};

float[] values = new float[]{2.0f, 6.0f};
aaaGraphView graphView = new aaaGraphView(this, values, "Graph One",
        horlabels, verlabels, aaaGraphView.BAR);

float[] values2 = new float[]{1.0f, 12.0f};
aaaGraphView graphView2 = new aaaGraphView(this, values2, "Graph Two",
        horlabels, verlabels, aaaGraphView.BAR);

and then to inflate graphView into ll_one, and graphView2 into ll_two.

How should I do this? I have initialized the LinearLayout

   llOne = (LinearLayout) findViewById(R.id.ll_one);

but it does not have inflate() method.

like image 531
sandalone Avatar asked Dec 05 '25 10:12

sandalone


1 Answers

You do not need to inflate another view inside your LinearLayout you'll just have to add another child inside that LinearLayout. Just use the addView() method on the LinearLayout that fits you the best. Here is an example :

   llOne.addView(graphView);
like image 169
Ovidiu Latcu Avatar answered Dec 08 '25 00:12

Ovidiu Latcu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!