关于网友提出的“关于LayoutParams”问题疑问,本网通过在网上对“关于LayoutParams”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题:关于LayoutParams
描述:public class CameraSurfaceView extends FrameLayout {
public static class SurfaceView extends android.view.SurfaceView {
public SurfaceView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setLayoutParams(new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
// setLayoutParams(new FrameLayout.LayoutParams(context, attrs));
}
}
private SurfaceView mSurfaceView;
public CameraSurfaceView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mSurfaceView = new SurfaceView(context, Xml.asAttributeSet(context
.getResources().getLayout(R.layout.csv_surfaceview)), defStyle);
addView(mSurfaceView);
}
}
用于反射的xml
android:layout_width="match_parent"
android:layout_height="match_parent" />
为什么自动解析失败
我看sdk里inflate也是差不多的啊
setLayoutParams(new FrameLayout.LayoutParams(context, attrs));
Logcat说必须提供android:layout_width
解决方案1: 你最好是 把三个 构造方法全实现 。每一个构造方法 里都要写
mSurfaceView = new SurfaceView(context, Xml.asAttributeSet(context
.getResources().getLayout(R.layout.csv_surfaceview)), defStyle);
addView(mSurfaceView);
解决方案2:mSurfaceView = new SurfaceView(context, Xml.asAttributeSet(context
.getResources().getLayout(R.layout.csv_surfaceview)), defStyle);
addView(mSurfaceView);
改成:
mSurfaceView = new SurfaceView(context);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
addView(mSurfaceView, params);
解决方案3: log说是你xml布局里有个控件少个宽的属性,你回头找找
以上介绍了“关于LayoutParams”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/640358.html