android – 在FrameLayout中的自定义视图上以编程方式设置边距值
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了android – 在FrameLayout中的自定义视图上以编程方式设置边距值,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1825字,纯文字阅读大概需要3分钟。
内容图文
![android – 在FrameLayout中的自定义视图上以编程方式设置边距值](/upload/InfoBanner/zyjiaocheng/776/3f41c7a82fb24103af6abd8e41fa8713.jpg)
我定义了一个视图.此视图包含图片,用户可以与之交互.我在主布局中定义了一个FrameLayout,并在此FrameLayout中以编程方式添加此视图.
在View构造函数中,我定义了一个MarginLayutParams,将此视图放在te屏幕的中心.代码是:
mLayoutParams = new MarginLayoutParams(picture.getWidth(), picture.getHeight);
mLayoutParams.setMargins(toCenterX, toCenterY, 0, 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);
}
@Override
protected 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, 0);
}
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
child.draw(canvas);
return true;
}
}
但是wheelCoreArea视图没有从左上角移动!
内容总结
以上是互联网集市为您收集整理的android – 在FrameLayout中的自定义视图上以编程方式设置边距值全部内容,希望文章能够帮你解决android – 在FrameLayout中的自定义视图上以编程方式设置边距值所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。