
╔═══════════════════════╗ ║ ║ ║ VIEw Group ║ ║ ║ ║ ╔═════════════╗ ║ ║ ║ ║ ║ ║ ║ ImageVIEw ║ ║ ║ ║ ║ ║ ║ ║ wIDth = X/2 ║ ║ ║ ║ height= X/2 ║ ║ ║ ╚═════════════╝ ║ ║ ║ ║ ║ ║ ║ ╚═══════════════════════╝ <----------------------->Xpx wIDth of Device/VIEwgroup
有人可以请帮助我如何实现这一目标?
解决方法 也许尝试这样的事情:public class CenteredImageVIEw extends ImageVIEw {public CenteredImageVIEw(Context context) { super(context);}public CenteredImageVIEw(Context context,AttributeSet attrs) { this(context,attrs,0);}public CenteredImageVIEw(Context context,AttributeSet attrs,int ID) { super(context,ID);}@OverrIDepublic voID onMeasure(int measureDWIDth,int measuredHeight) { super.onMeasure(measureDWIDth,measuredHeight); VIEwGroup parent = (VIEwGroup) getParent(); if(parent != null){ int wIDth = parent.getMeasureDWIDth() / 2; setMeasuredDimension(wIDth,wIDth); }} 可能没有必要对父进行空检查,但应相应地调整图像大小
总结以上是内存溢出为你收集整理的android – 将ImageView放在中心,宽度和高度是父宽度的一半?全部内容,希望文章能够帮你解决android – 将ImageView放在中心,宽度和高度是父宽度的一半?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)