Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中缩放和滚动imageView_Android_Imageview_Scrollview_Zooming - Fatal编程技术网

如何在android中缩放和滚动imageView

如何在android中缩放和滚动imageView,android,imageview,scrollview,zooming,Android,Imageview,Scrollview,Zooming,我知道这个问题已经详细讨论过了,我知道并尝试过一些解决方案,包括“TouchImageView”。但我的问题略有不同。我想滚动图像,而无需借助运动、手势或任何触摸事件。我正在使用ScrollView来解决这个问题,我认为它可以解决这个问题 我正在使用ZoomController小部件,只是调整imageView的缩放功能以进行放大和缩小 问题是ScrollView没有响应。。。如有任何建议,将不胜感激 下面是我的XML和MainActivity类代码 活动\u缩放\u image.xml <

我知道这个问题已经详细讨论过了,我知道并尝试过一些解决方案,包括“TouchImageView”。但我的问题略有不同。我想滚动图像,而无需借助运动、手势或任何触摸事件。我正在使用ScrollView来解决这个问题,我认为它可以解决这个问题

我正在使用ZoomController小部件,只是调整imageView的缩放功能以进行放大和缩小

问题是ScrollView没有响应。。。如有任何建议,将不胜感激

下面是我的XML和MainActivity类代码

活动\u缩放\u image.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context="${packageName}.${activityClass}" >

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical" >

    <ScrollView
        android:id="@+id/scroll_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:contentDescription="@string/zoom"
            android:isScrollContainer="true"
            android:src="@drawable/eiff" />
    </ScrollView>

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:orientation="vertical" >

    <ZoomControls
        android:id="@+id/zoomControls1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />
</LinearLayout>

ZoomImage.java的oncreate方法

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(new Zoom(this));
    setContentView(R.layout.activity_zoom_image);

    image = (ImageView) findViewById(R.id.imageView1);
    zoom = (ZoomControls) findViewById(R.id.zoomControls1);
    bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.eiff);
    image.setImageBitmap(bitmap);

    zoom.setOnZoomInClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            float x = image.getScaleX();
            float y = image.getScaleY();

            image.setScaleX((float) (x+1));
            image.setScaleY((float) (y+1)); 
        }
    });

    zoom.setOnZoomOutClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            float x = image.getScaleX();
            float y = image.getScaleY();
            if (x <= 1 || y <= 1)
                return;
            image.setScaleX((float) (x-1));
            image.setScaleY((float) (y-1));
        }
    });

}
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//setContentView(新缩放(此));
setContentView(R.layout.activity\u zoom\u image);
image=(ImageView)findViewById(R.id.imageView1);
zoom=(ZoomControl)findViewById(R.id.ZoomControl 1);
位图=BitmapFactory.decodeResource(getResources(),R.drawable.eiff);
setImageBitmap(位图);
setOnZoomInClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
float x=image.getScaleX();
float y=image.getScaleY();
image.setScaleX((浮点)(x+1));
图.设置刻度((浮动)(y+1));
}
});
setOnZoomOutClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
float x=image.getScaleX();
float y=image.getScaleY();

如果(x尝试使用一个外部jar文件,比如pinchzoom.jar,只需在谷歌上搜索它,你就可以找到一个,并提供相关说明

这是链接,试试看……干杯


<ScrollView
    android:id="@+id/scroll_1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:contentDescription="@string/zoom"
        android:isScrollContainer="true"
        android:src="@drawable/eiff" />
</ScrollView>

<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:orientation="vertical" >

    <ZoomControls
        android:id="@+id/zoomControls1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />
</LinearLayout>

请在您的答案中添加全面的描述。只包含参考链接的答案是非常不鼓励的,因为当链接不再工作时,这样的答案将变得毫无用处!@vinay.sasalati Thankx…但我已经尝试了不同的自由库,是的,它们工作了…我想知道我解决这个问题的方法是否正确,如果是,那么我该怎么做才能使它工作…@muak,尝试将您的xml更改为下面给出的格式。@vishwayer是的,它工作了。…这是图像出了secreen,我必须滚动它才能查看它…它不工作了…我使用完全相同的xml,但将其包装在相对布局中…仍然没有滚动我不确定它对您不起作用,但它对您不起作用ns在我的模拟器中非常完美。我可以用TouchEvent完成这项工作……如果您能给我发送工作功能的源代码,我将不胜感激。。。。