在VIEw构造函数中,我定义了一个marginLayutParams,将此视图放在te屏幕的中心.代码是:
mLayoutParams = new marginLayoutParams(picture.getWIDth(),picture.getHeight);mLayoutParams.setmargins(toCenterX,toCenterY,0);setLayoutParams(mLayoutParams);
边距值不起作用…视图正确调整为宽度和高度定义,但视图不是按边距值缩放到视图的中心…
编辑:
我的观点的模式:
-> VIEw1 (i want sclae this vIEw to the center)Activity -> FrameLayout -> VIEw2 (i want scale this vIEw under the vIEw 1) -> VIEw3 (i want scale this vIEw at the top right)
这是我的VIEwGroup示例.我实现了一个VIEwGroup来管理所有视图:
public class MainVIEw extends VIEwGroup {public BackgroundVIEw mBackgrounDWheelArea;public BackgroundVIEw mBackgroundLabelArea;public WheelCoreVIEw wheelCoreArea;public LabelVIEw labelArea;public WheelOfFortuneActivity mActivity;public MainVIEw(Context pContext) { super(pContext); mActivity = (WheelOfFortuneActivity) pContext; mBackgrounDWheelArea = new BackgroundVIEw(pContext,R.drawable.menu_background); wheelCoreArea = new WheelCoreVIEw(pContext,mActivity.fromPixelToDp(mBackgrounDWheelArea .getBackgroundHeight()),mActivity.fromPixelToDp(mBackgrounDWheelArea .getBackgrounDWIDth())); labelArea = new LabelVIEw(pContext,"Web"); mBackgroundLabelArea = new BackgroundVIEw(pContext,R.drawable.menu_background_label); this.addVIEw(wheelCoreArea,0);}@OverrIDeprotected voID onLayout(boolean pChanged,int pL,int pT,int pR,int pB) { final int count = getChildCount(); for (int i = 0; i < count; i++) { VIEw child = getChildAt(i); child.layout(100,100,0); }}@OverrIDeprotected boolean drawChild(Canvas canvas,VIEw child,long drawingTime) { child.draw(canvas); return true;}}
但是wheelCoreArea视图没有从左上角移动! 总结
以上是内存溢出为你收集整理的android – 在FrameLayout中的自定义视图上以编程方式设置边距值全部内容,希望文章能够帮你解决android – 在FrameLayout中的自定义视图上以编程方式设置边距值所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)