我有一个ImageView
在android中。我想要将图像部分移动到屏幕内,以便只能看到图像的一部分。如果我在xml中设置了边距或填充,图像会缩小。我在onCreate
方法中使用了翻译Animation
。但是当我第一次看到视图时,我看到图像在移动。我希望图像能够部分可见,而不会看到移位。有没有办法做到这一点?在android中移动图像部分在屏幕上移动
6
A
回答
2
这个怎么样。
在你活动的onCreate:
ImageView yourImage = (ImageView)findViewById(R.id.your_image_control_id);
yourImage.setX(1000);
yourImage.setY(1000);
这样一来,它在启动时正确定位。或者你可以使用AbsoluteLayout并以这种方式设置图像的x和y坐标。确保你没有使用fill_parent作为高度或宽度。
+3
我的API是2.1和更高。 SetX来自API 11.不是绝对布局已弃用。 – user866821
4
父视图
(如LinearView
)设置ClipChildrens=false
,如果你正在寻找
检查这个代码,它的工作对我来说...
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="-20dp"
android:src="@drawable/ic_launcher" />
</FrameLayout>
2
我发现,如果你使用负边缘,那么你不能在对面的alignParent,所以,假设你想让图像在视图的右边放一半,你不能指定android:layout_alignParentLeft。另外,如果您需要完整图像并且不希望它被剪裁,就像在想要在全屏幕上点击动画的情况下一样,您必须设置父级布局android:clipChildren =“false”。以下XML DEF对我的作品:
<ImageView
android:id="@+id/you_feature_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="@dimen/feature_margin_right"
android:contentDescription="feature_image"
android:gravity="center_vertical"
android:padding="@dimen/zero"
android:paddingBottom="@dimen/zero"
android:paddingLeft="@dimen/zero"
android:paddingRight="@dimen/zero"
android:paddingTop="@dimen/zero"
android:src="@drawable/feature_phone_02_2x" />
我张贴这个,因为我只烧了几个小时试图弄清楚这一点我自己,想也许这会帮助别人在未来,他们应该来像我一样在这个问题上。
相关问题
- 1. 在移动屏幕上获取可移动屏幕上的可见部分(放大图像),在HTML中
- 2. 在屏幕上移动图像
- 3. Android TranslateAnimation - 将屏幕右侧的图像移动到屏幕上
- 4. 如何在Android上的屏幕上移动图像
- 5. MKMapView在屏幕上移动
- 6. 停止图像屏幕上移动
- 7. 如何在整个屏幕上平滑地移动图像Android
- 8. 从左侧屏幕外部移动图像到右侧屏幕外部Android
- 9. Android在屏幕边界内移动图像
- 10. 将屏幕移动到屏幕上
- 11. Android移动图像视图到屏幕中心
- 12. 让图像在屏幕上自由移动
- 13. 如何在屏幕上移动图像触摸?
- 14. 在屏幕上移动一个小图像
- 15. Pygame独立移动图像在屏幕上
- 16. 如何使图像在黑莓屏幕上移动
- 17. 如何在屏幕上移动完美的图像?
- 18. 在图像上移动 - 大于屏幕尺寸
- 19. monotouch获取图像在屏幕上移动
- 20. 滚动android屏幕上的图像屏幕上的图像
- 21. 如何在Android屏幕上识别视图移动?
- 22. AS3 - 在屏幕上移动MovieClip
- 23. UIPopoverController可以在屏幕上移动吗?
- 24. 使用NSMutablearray在屏幕上移动UILabels
- 25. 如何在屏幕上移动对象
- 26. 在expandablelistview的屏幕顶部移动/滚动点击listitem视图
- 27. JS在屏幕上移动图像并在末尾加载另一个图像
- 28. 图片在iOS中用手指在屏幕上移动
- 29. 在移动Safari中的屏幕外缓存图像
- 30. 如何移动,并在屏幕的中心旋转图像
如果可能,您是否可以发布图片视图代码? – EpicOfChaos
你有什么高度和宽度设置?如果您将它们设置为比您的屏幕大小更大的值,则应该可以使用边距或填充将其移动到任何需要的位置。您的布局也必须大于屏幕尺寸。 – FoamyGuy
没有imageView代码。我将图像放入xml文件中。 – user866821