
我在absoluteLayout中有两个ImageVIEw.
<absoluteLayout androID:ID="@+ID/absoluteLayout01" androID:layout_wIDth="fill_parent" androID:background="@drawable/whitebackground" androID:layout_height="fill_parent" xmlns:androID="http://schemas.androID.com/apk/res/androID"><ImageVIEw androID:ID="@+ID/floorPlanBackgroundImage" androID:src="@drawable/ic_tab_lights_gray" androID:scaleType="center" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content"></ImageVIEw><ImageVIEw androID:ID="@+ID/fplight" androID:src="@drawable/ic_tab_lights_gray" androID:scaleType="center" androID:layout_x="50px" androID:layout_y="50px" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content"></ImageVIEw></absoluteLayout>floorPlanBackgroundImage是从800×600大小的图像动态设置的.可以围绕它滚动.
我的第二张图片,fplight代表房间里的灯光.这是一个小的20×20图像.我需要做的是改变layout_x&代码中的layout_y属性,但我没有看到在ImageVIEw中设置它的方法.
我期待这样的事……
fplight.setLayoutX( “55像素”);
有办法吗?
解决方法:
你应该使用:
absoluteLayout.LayoutParams param = new absoluteLayout.LayoutParams(int wIDth, int height, int x, int y)layout使用首选x和y的参数对象,并将其设置为fplight图像
fplight.setLayoutParams(param);absoluteLayout已弃用
您应该使用relativeLayout
例:
假设你想要一个尺寸为50×60的ImageVIEw(位置为70×80)
// relativeLayout. though you can use xml relativeLayout here too by `findVIEwByID()`relativeLayout relativeLayout = new relativeLayout(this);// ImageVIEwImageVIEw imageVIEw = new ImageVIEw(this);// Setting layout params to our relativeLayoutrelativeLayout.LayoutParams layoutParams = new relativeLayout.LayoutParams(50, 60);// Setting position of our ImageVIEwlayoutParams.leftmargin = 70;layoutParams.topmargin = 80;// Finally Adding the imageVIEw to relativeLayout and its positionrelativeLayout.addVIEw(imageVIEw, layoutParams); 总结 以上是内存溢出为你收集整理的Android – 以编程方式设置图像的X,Y.全部内容,希望文章能够帮你解决Android – 以编程方式设置图像的X,Y.所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)