让自定义的view滚动起来

1. 首先,继承View的类下要有重写onMeasure()方法,其中setMeasuredDimension()方法一定要写,这样在插入到scrollView里的时候才可以设置你的宽高。

代码如下:

   @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if(imageBitmap != null){ setMeasuredDimension(200, 400); } } 

 

2. 在你的Activity里的代码是:

ScrollView mScrollView = new ScrollView(this); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT); DrawUtil2 duView = new DrawUtil2(this , name); mScrollView.addView(duView); setContentView(mScrollView , params); 

 

你可能感兴趣的:(让自定义的view滚动起来)