我已創建自己的ViewGroup。我已經添加了一個小部件到視圖中,我從Eclipse Design Editor中得到一個錯誤(我需要一個預覽來獲得更快/更好的開發)。自定義ViewGroup
public class MyViewGroup extends LinearLayout {
public MyViewGroup(Context context, AttributeSet attrs) {
super(context, attrs);
this.addView(new EditText(context)); // The Error Line
}
...
}
隨着的LayoutParams鴕鳥政策改變什麼:
this.addView(new Button(mcontext),
new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<...MyViewGroup android:layout_height="match_parent" android:layout_width="match_parent" android:layout_margin="2dip" android:id="@+id/Token01"> </...MyViewGroup>
</LinearLayout>
我不看它在模擬器上。如果我刪除「錯誤行」,設計器不會出錯。什麼是我的失敗或無法呈現Eclipse Designer?但是爲什麼我在仿真器/設備上看不到它?我的目標是使用自定義視圖和無XML的ViewGroup創建此部分。
我希望你能幫助我,對不起我的英語不好。
謝謝。
感謝您的回答。該守則永遠不會運行。可視化編輯器顯示錯誤並且登錄模擬器不顯示EditText。 – Tim