Android的 - 设置X,Y图像编程 [英] Android - setting X,Y of image programmatically

查看:120
本文介绍了Android的 - 设置X,Y图像编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有内部的AbsoluteLayout 2 ImageViews。

I have two ImageViews inside an AbsoluteLayout.

<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而动态图像,其尺寸为800x600设置。在可以围绕它滚动。

the floorPlanBackgroundImage is dynamically set from an image that is 800x600 in size. The can scroll around it.

我的第二个图像,fpLight重新presents在一个房间里的光。这是一个小20x20的图像。我需要做的是改变layout_x和放大器;在code layout_y属性,但我不明白的方式来设置在ImageView的。

My second image, fpLight represents a light in a room. It's a small 20x20 image. What I need to do is change the layout_x & layout_y properties in code, but I don't see a way to set that in the ImageView.

我早料到这样的事情...

I'd expected something like this...

fpLight.setLayoutX(55像素);

fpLight.setLayoutX("55px");

有没有办法?

推荐答案

您应该使用:

AbsoluteLayout.LayoutParams param = new AbsoluteLayout.LayoutParams(int width, int height, int x, int y)

与preferred x和y

布局参数对象,并将其设置为您fpLight形象

layout Parameter object with the preferred x and y and set it to your fpLight image by

fpLight.setLayoutParams(param);

这篇关于Android的 - 设置X,Y图像编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆