Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 图像视图位置和大小_Java_Android_Imageview - Fatal编程技术网

Java 图像视图位置和大小

Java 图像视图位置和大小,java,android,imageview,Java,Android,Imageview,我有一个用XML定义的ImageView,稍后我将其膨胀以供使用 我希望在一个点是大小400200(宽度,高度),在另一个点(500300)。 我还想把它放在屏幕上的特定位置,比如设置x,y坐标(或者Rect(左,上,右,下)会很好) 我明白为此我必须“玩”LayoutParameters,但我找不到任何具体的信息如何做。 任何人都可以举几行例子来理解这一点……如果你想在父节点的指定点上,你可以在px或dp中指定android:layout\u marginLeft和android:layout

我有一个用XML定义的ImageView,稍后我将其膨胀以供使用

我希望在一个点是大小400200(宽度,高度),在另一个点(500300)。 我还想把它放在屏幕上的特定位置,比如设置x,y坐标(或者Rect(左,上,右,下)会很好)

我明白为此我必须“玩”LayoutParameters,但我找不到任何具体的信息如何做。
任何人都可以举几行例子来理解这一点……

如果你想在父节点的指定点上,你可以在px或dp中指定
android:layout\u marginLeft
android:layout\u marginTop
。它不是很清楚,但很有效。

通过编程,您可以调用
View.layout(int,int,int,int)
,但我找不到相同的XML参数。

如果您想动态更改代码中imageview的位置,您只能通过设置其边距来更改位置,使其左/右和上/下移动。下面接收ImageView的布局参数,以便您可以更改视图的边距

ImageView image;
// Gets the layout params of the imageview
MarginLayoutParams params = (MarginLayoutParams)image.getLayoutParams();
// Sets the margins of the imageview, making it move to a specific location on the screen
param.setMargins(int left, int top, int right, int bottom);

是的,我需要它的编程。。我用scaleType“fitXY”定义了ImageView,然后执行iv.setMargins(100100,0,0)-期望它向下100像素,向左100像素。它不会从上角移动…您可以使用
View.layout(intl,intt,intr,intb)
方法。请参阅以在代码中指定您拨打电话的位置。