簡體   English   中英

如何將另一個視圖膨脹為LinearLayout?

[英]How to inflate another view into LinearLayout?

這是我的2個LinearLayouts XML。

<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。 這個類擴展了View。 我基本上想要初始化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()方法。

您不需要在LinearLayoutinflate另一個view ,您只需要在該LinearLayout添加另一個子view 只需在LinearLayout上使用最適合您的addView()方法。 這是一個例子:

   llOne.addView(graphView);

如果擴展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>

試試這種方式我已經將linearlayout添加到另一個線性布局中,

setContentView(R.layout.main);
final ViewGroup vg = (ViewGroup) findViewById(R.id.ll_one);
vg.addView(graphView);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM