我有一個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