android–ImageView setMargins不起作用

android–ImageView setMargins不起作用,第1张

概述我有一个FrameLayout有2个图像,一个填充FrameLayout的大图像和一个我想要移动的非常小的图像.我试着像这样移动一个小的:xml文件<FrameLayoutandroid:id="@+id/layTrackMap"android:layout_width="wrap_content"an

我有一个FrameLayout有2个图像,一个填充FrameLayout的大图像和一个我想要移动的非常小的图像.

我试着像这样移动一个小的:
xml文件

   <FrameLayout androID:ID="@+ID/layTrackMap"                      androID:layout_wIDth="wrap_content"                                androID:layout_height="wrap_content"                               androID:visibility="gone">         <ImageVIEw androID:ID="@+ID/imgTrackMap"                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"               />         <ImageVIEw androID:ID="@+ID/imgposition"                androID:layout_wIDth="wrap_content"               androID:src="@drawable/position"                androID:layout_height="wrap_content"               />         </FrameLayout>   

和代码:

imgposition = (ImageVIEw)findVIEwByID(R.ID.imgposition);    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);    //Neither this:    //lp.setmargins(30, 20, 0, 0);    //Or this    lp.leftmargin=30;    lp.topmargin=80;    imgposition.setLayoutParams(lp);

小图像不会移动.我希望能够在布局中移动小图像.

后期编辑:
在尝试了几个建议后,我得出结论,只需创建一个自定义view并覆盖onDraw就可以完成这项工作.

解决方法:

FrameLayout中的所有内容都固定在左上角,即使设置边距也无法移动.但是你可以通过使用填充来获得相同的结果……

imgposition.setpadding(30, 80, 0, 0);
总结

以上是内存溢出为你收集整理的android – ImageView setMargins不起作用全部内容,希望文章能够帮你解决android – ImageView setMargins不起作用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1120105.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存