我有一个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. 在屏幕IOS上移动图像?
- 4. 如何在屏幕上移动图像?
- 5. 使图像在Python中移动屏幕
- 6. Android TranslateAnimation - 将屏幕右侧的图像移动到屏幕上
- 7. 在android中的屏幕上移动一个图像按钮
- 8. 如何在Android上的屏幕上移动图像
- 9. 在屏幕上移动UIbutton
- 10. MKMapView在屏幕上移动
- 11. 停止图像屏幕上移动
- 12. Android如何控制图像只能在屏幕上移动?
- 13. 如何在整个屏幕上平滑地移动图像Android
- 14. 在Android中使用移动图像截取屏幕截图
- 15. 如何在移动灵活视图的屏幕上随机移动图像?
- 16. 从左侧屏幕外部移动图像到右侧屏幕外部Android
- 17. 在Android中移动图像
- 18. 在屏幕上显示一个正在移动的图像
- 19. 图像在小屏幕上的导航栏上移动
- 20. 试图使用jquery在屏幕上移动我的图像
- 21. Android屏幕随AdView移动
- 22. 在iphone上的屏幕上移动UIView
- 23. Android在屏幕边界内移动图像
- 24. 将屏幕移动到屏幕上
- 25. Android移动图像视图到屏幕中心
- 26. 让图像在屏幕上自由移动
- 27. 如何在屏幕上移动jlabel图像?
- 28. monotouch获取图像在屏幕上移动
- 29. 在移动网站上缩放图像以适应屏幕
- 30. Pygame独立移动图像在屏幕上
如果可能,您是否可以发布图片视图代码? – EpicOfChaos
你有什么高度和宽度设置?如果您将它们设置为比您的屏幕大小更大的值,则应该可以使用边距或填充将其移动到任何需要的位置。您的布局也必须大于屏幕尺寸。 – FoamyGuy
没有imageView代码。我将图像放入xml文件中。 – user866821