我知道如何顯示比屏幕更大的圖像。這很簡單,詳細解釋here,然而,這種方法使你能夠儘可能地滾動,事件如果你已經離開了圖像,你只是有黑屏。我想知道當我們到達圖片的一側時我們如何使滾動停止...滾動比屏幕更大的圖像,並停止在Android的邊框上
回答
將您的圖像加載到WebView中。然後,您將獲得您正在查找的所有滾動行爲,甚至是默認的縮放控件,如果您選擇打開它們......實際上是免費的。 (據我所知),您唯一的選擇是使用2D圖形API(Canvas等)並創建您自己的繪圖切片版本(如查看地圖的一部分)。
如果您的圖片是本地的,請參閱from the SD Card中讀取本地圖像數據的示例。在這種情況下,提供本地圖像的更簡潔的方法是創建ContentProvider並通過WebView中的content:// URL訪問資源。
示例使用捆綁的圖像car.jpg
在assets
目錄中的項目:
RES /佈局/ main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="@+id/web"
android:layout_width="150dip"
android:layout_height="150dip"
/>
</LinearLayout>
的src/ImageViewer.java
public class ImageViewer extends Activity {
WebView webView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView)findViewById(R.id.web);
webView.loadUrl("file:///android_asset/car.jpg");
}
}
對於與您的項目捆綁在一起的圖像,這是最簡單的方法。這不適用於資源目錄中的圖像(如res/drawable)。該路徑不值得完成它所需的代碼。
感謝您的回答,我會盡力花點時間看看這一切,明天再回來一些反饋。thx guys – Sephy 2010-08-18 22:31:08
好吧,現在第一個問題,我無法在Web視圖中設置此圖像,因爲無論我將它作爲webview的背景並且圖像被調整大小,或者我嘗試從資源加載它, t解決它。 (我認爲這是一個路徑問題......我知道我可以從資產中做到這一點,但我會喜歡它來自res/drawable),並且由於我沒有屏幕的大小,所以我沒有知道怎麼把寬度和高度放在img src – Sephy 2010-08-21 12:25:21
從文件系統或資產中加載捆綁的圖像是通過FAR處理WebView時的最簡單的方法(我用一個例子編輯)。這是因爲Android已經構建了爲AssetManager服務的內容......並且這不適用於其他資源。您必須在自定義ContentProvider的'openFile()'方法中複製行爲'AssetManager.openFd()'。這是更多的代碼。 – Devunwired 2010-08-22 21:09:48
在你Activity.onCreate():
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(...);
我不知道哪個佈局你到底是說,所以我發佈2個版本:
版本1(布頓在圖片下方):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
android:fadingEdge="none" android:scrollbars="none">
<ImageView android:id="@+id/image" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:scaleType="center" />
</ScrollView>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="OK"
android:layout_gravity="center" />
</LinearLayout>
版本2(按鈕在圖像 - 在z軸上):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:fadingEdge="none"
android:scrollbars="none">
<ImageView android:id="@+id/image" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:scaleType="center" />
</ScrollView>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="OK"
android:layout_gravity="bottom|center_horizontal" />
</FrameLayout>
您也可以嘗試將ScrollView放入HorizontalScrollView中。這裏
嗯,我有同樣的問題,是我的解決方案:
Display display = getWindowManager().getDefaultDisplay();
screenSize = new Point();
display.getSize(screenSize);
得到它會被要求設置底部和右側邊界
image.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
float curX, curY;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mx = event.getX();
my = event.getY();
rect = image.getDrawable().getBounds();
break;
case MotionEvent.ACTION_MOVE:
curX = event.getX();
curY = event.getY();
image.scrollBy(getX((int) (mx - curX)), getY((int) (my - curY)));
mx = curX;
my = curY;
break;
}
return true;
}
});
最後兩種方法來設定新的滾動座標屏幕尺寸
private int getX(int x){
if (image.getScrollX() + x < 0){ //left side
return 0;
} else if (image.getScrollX() + x >= (rect.right - screenSize.x)){ //right side
return 0;
} else {
return x;
}
}
private int getY(int y){
if (image.getScrollY() + y < 0){ //top side
return 0;
} else if (image.getScrollY() + y >= (rect.bottom - screenSize.y)){ //bottom side
return 0;
} else {
return y;
}
}
很好的API 16+,希望能幫到
- 1. 滾動android屏幕上的圖像屏幕上的圖像
- 2. 停止圖像屏幕上移動
- 3. 如何停止屏幕上的圖像?
- 4. 滾動到滾動型/滾動視圖停止滾動特定的文本框,當鍵盤在屏幕上
- 5. 停止滾動屏幕的pygame文本
- 6. 圖像比屏幕大
- 7. 顯示和滾動比屏幕更長的UIImageView(圖像)
- 8. WPF在屏幕上移動的邊框
- 9. 停止滾動一次最後的li在屏幕上可見
- 10. 大,長的圖像以不同的速度在屏幕上滾動,並且離開屏幕的左側
- 11. 完成修復屏幕上滾動條內的大圖像?
- 12. 如何在屏幕上向下滾動200px後更改圖像的大小。
- 13. 浮動左邊,但在屏幕上的某個點停止調整大小?
- 14. mobi網站動畫在手機屏幕上滾動時停止
- 15. 停止在y軸上滾動邊欄
- 16. Android TranslateAnimation - 將屏幕右側的圖像移動到屏幕上
- 17. 在屏幕邊緣停止UIPageViewController
- 18. Android小工具:TextView的字幕停止在主頁上滾動
- 19. 滾動Android視圖/大於屏幕大小的表格
- 20. 分享圖像畫在比屏幕本身更大的圖形上
- 21. 如何停止用戶停止觸摸屏幕uiscrollview滾動
- 22. 停止js圖像彈出屏幕
- 23. iOS:如何創建並繪製(並保存)比屏幕更大的圖像?
- 24. View.Invisible - 圖像停留在屏幕上
- 25. 填充屏幕和滾動時圖像的高寬比
- 26. 我在UIView中的圖像看起來比在初始屏幕上更大
- 27. Android/Eclipse:與屏幕邊框匹配的圖像
- 28. 如何停止屏幕邊框的文字?
- 29. 滾動條讓屏幕更大
- 30. 如何居中比屏幕更大的圖像?
沒有人有關於此的任何提示?我應該直接在Canvas上使用SurfaceView嗎? – Sephy 2010-08-17 14:13:18