4

画像をスライドできる UIScrollView の Android に相当するものはありますか。ありがとうございました。

申し訳ありませんが、私はより具体的ではありませんでした。私はあらゆる方向にスライドする必要があります。Android の ScrollView はこれを行いません。私は動作する WebView を使用していますが、4.0 以降でしか動作しないようです。


これが私が思いついたものです。ImageView を WebView 内に配置し、ImageView に setOnTouchListener を割り当てました。うまくいきそうです。

  web = new WebView(this);
  web.setVerticalScrollBarEnabled(false);
  web.setHorizontalScrollBarEnabled(false);
  web.setBackgroundColor(Color.RED);
  web.setId(100);
  RelativeLayout.LayoutParams layoutForContainer = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    layoutForContainer.height = 300;
    layoutForContainer.width = 300;
    layoutForContainer.addRule(RelativeLayout.CENTER_IN_PARENT);
    web.setLayoutParams(layoutForContainer);     
  layout.addView(web);

  myImageView = new ImageView(this);
  myImageView.setImageResource(R.drawable.myImage); 
  RelativeLayout.LayoutParams layoutForLargeImage = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
  layoutForLargeImage.height = (int) 768;
  layoutForLargeImage.width = (int) 1024;
  myImageView.setLayoutParams(layoutForLargeImage); 
  web.addView(myImageView);

  myImageView.setOnTouchListener(new View.OnTouchListener() {
    float downX, downY;
    int scrollByX, scrollByY;
    public boolean onTouch(View view, MotionEvent event) {
        float currentX, currentY;
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                downX = event.getX();
                downY = event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                currentX = event.getX();
                currentY = event.getY();
                scrollByX = (int)(downX - currentX);
                scrollByY = (int)(downY - currentY);

                myImageView.scrollBy(scrollByX, scrollByY);
                downX = currentX;
                downY = currentY;

                break;
        }
        return true;
    }
});
4

4 に答える 4

1

明らかに、 UIScrollView のような多くのオプションがあります。(1) Horizo​​ntalScrollViewを取ることができます (2) Viewpager を取ることができます

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >  

 <WebView
            android:id="@+id/webview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />                   
</RelativeLayout>
于 2013-09-27T06:15:50.573 に答える