我想创建一个包含两个按钮而不使用xml的自定义视图。不使用XML创建自己的自定义视图
我尝试这样做:
public class ZoomPlate extends LinearLayout {
private Context context;
private Button plus;
private Button minus;
public ZoomPlate(Context context) {
super(context);
init(context);
}
public ZoomPlate(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context) {
this.context = context;
LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,0);
plus = new Button(context);
plus.setText("Plus");
plus.setLayoutParams(params);
minus = new Button(context);
minus.setText("Minus");
minus.setLayoutParams(params);
setOrientation(LinearLayout.VERTICAL);
addView(plus);
addView(minus);
}
}
,这样我就可以使用ZoomPlate在XML就像一个按钮,或者像一个TextView:
<at.bartinger.zoomplate.ZoomPlate
android:id="@+id/zoomplate"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
但是当我尝试这个没有被显示
是的,我知道如何在xml中写这个。问题是Viewobject – 2010-10-05 09:08:55