我已经创建了自己的 ViewGroup。我已经在视图中添加了一个小部件,但我从 Eclipse 设计编辑器中得到了一个错误(我需要一个预览以实现更快/更好的开发)。
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 创建此部分。
我希望你能帮助我,并为我糟糕的英语感到抱歉。
谢谢你。