gpt4 book ai didi

android - 动态改变 ImageView 的位置

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:49:55 27 4
gpt4 key购买 nike

我目前正在使用矩阵方法为图像(图像A)实现拖动和捏合缩放

现在我希望图像 A 的一部分可以点击,所以我将另一个 ImageView (图像 B)放在图像 A 上,并在 xml 文件中为其设置 layout_margins。

我的问题是......有没有办法在我缩放图像以进行拖动和捏合缩放时动态更改我的 layout_margins?

我想更简单的问题是...如何动态设置 ImageView 的 layout_margins?

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ImageView android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/map"
android:scaleType="matrix" />

<ImageView
android:id="@+id/dundas_station"
android:layout_width="75px"
android:layout_height="75px"
android:layout_marginTop="337px"
android:layout_marginLeft="373px"
android:clickable="true"
android:src="@drawable/google_maps_icon"
android:scaleType="matrix"
/>
</RelativeLayout>

谢谢!

最佳答案

使用以下代码 fragment 。不要忘记导入“android.widget.FrameLayout.LayoutParams”或边缘布局参数。

ImageView image;
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(100,0, 0,0);

// OR
params.topMargin= 100;
image.setLayoutParams(params);

关于android - 动态改变 ImageView 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4311044/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com