在机器人的滚动型图像 [英] Images in ScrollView in android

查看:92
本文介绍了在机器人的滚动型图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序我要放置一个PNG文件,我希望它被看作是在风景和肖像模式,一个滚动的图像,请提出一个code或例如......

In my app I want to place a .png file and I want it to be viewed as a scrolled image at both landscape and portrait modes, please, suggest a code or example....

推荐答案

一个简单的解决方案是滚动的容器,其中包含一个ImageView的比集装箱更大的:

A simple solution is to scroll a container which contains an ImageView much bigger than the container:

<?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:gravity="center"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/Container"
        android:layout_width="200dp"
        android:layout_height="200dp" >

        <ImageView
            android:id="@+id/ImageView01"
            android:layout_width="480dp"
            android:layout_height="800dp"
            android:src="@drawable/sky_bgr" >
        </ImageView>
    </LinearLayout>

</LinearLayout>

然后用code滚动它:

And then use code to scroll it:

public class StartActivity extends Activity {
    private LinearLayout container;   
    private int currentX;   
    private int currentY; 

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
        container = (LinearLayout) findViewById(R.id.Container);
        container.scrollTo(220, 400);
    }

    @Override  
    public boolean onTouchEvent(MotionEvent event) { 
      switch (event.getAction()) { 
          case MotionEvent.ACTION_DOWN: { 
              currentX = (int) event.getRawX(); 
              currentY = (int) event.getRawY(); 
              break; 
          } 

          case MotionEvent.ACTION_MOVE: { 
              int x2 = (int) event.getRawX(); 
              int y2 = (int) event.getRawY(); 
              container.scrollBy(currentX - x2 , currentY - y2); 
              currentX = x2; 
              currentY = y2; 
              break; 
          }    
          case MotionEvent.ACTION_UP: { 
              break; 
          } 
      } 
        return true;  
    } 
}

下面许多可以改进的,如限制滚动范围等... 另一种方法是控制的ImageView矩阵... 然后你就可以将图像加载到一个位图,并绘制它在画布等部分

Here many improvements can be made such as limit the scrolling range etc... The other way is to control ImageView's matrix... Then you can load an image into a bitmap and draw a portion of it on canvas etc

这篇关于在机器人的滚动型图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆