layout_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
tools:context=".MainActivity" >
<com.example.testandroid.MainView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
主视图:
public class MainView extends ViewGroup {
public MainView(Context context, AttributeSet as) {
super(context);
addView(new ZoomController(context));
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
for (int i = 0, len = getChildCount(); i < len; i++) {
View v = getChildAt(i);
v.layout(0, 0, r - l, b - t);
}
}
}
缩放控制器:
public class ZoomController extends LinearLayout {
private Button zoomIn;
public ZoomController(Context context) {
super(context);
zoomIn = new Button(context);
zoomIn.setText("+");
setOrientation(1);
addView(zoomIn);
}
}
当我运行应用程序时,我得到一个空白屏幕。
为什么zoomIn
按钮不可见?