2

这是我的 XML 与 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>

我已经从http://android.arnodenhond.com/components/graphview下载了 GraphView 。此类扩展视图。我基本上想通过初始化2个图

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

然后膨胀graphViewll_one,然后graphView2ll_two

我该怎么做?我已经初始化了LinearLayout

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

但它没有inflate()方法。

4

3 回答 3

5

你不需要在你的inflate另一个view里面你LinearLayout只需要在里面添加另一个孩子LinearLayout。只需使用最适合您的addView()方法即可。LinearLayout这是一个例子:

   llOne.addView(graphView);
于 2011-10-17T10:14:00.827 回答
3

如果扩展 View 的类的名称是 aaaGraphView 试试这个:

<package1.package2....aaaGraphView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

</package1.package2....aaaGraphView>
于 2011-10-17T10:13:15.453 回答
3

尝试这种方式,我以这种方式将线性布局添加到另一个线性布局中,

setContentView(R.layout.main);
final ViewGroup vg = (ViewGroup) findViewById(R.id.ll_one);
vg.addView(graphView);
于 2011-10-17T10:13:44.897 回答