【问题标题】:How to make Imageview bigger than screen size in android?如何使Imageview大于Android中的屏幕尺寸?
【发布时间】:2022-07-14 14:17:24
【问题描述】:

我是 android 的初学者,我想知道如何上传大于屏幕尺寸的图像并能够拖动它?我应该使用什么布局以及如何进行拖动?只要说出我应该使用什么以及我应该阅读什么。

【问题讨论】:

  • 你从哪里得到的图片?
  • 来自 Drawable 文件夹
  • 然后直接从drawable文件夹上传。与大小或分辨率、布局和拖动无关。
  • 很抱歉我的问题不清楚,我的意思是如何让 Imageview 大于屏幕尺寸
  • 那你为什么还在谈论上传?我不能跟着你。

标签: android view imageview


【解决方案1】:

这是你要找的吗?

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical"
   android:padding="14dp"
   android:gravity="center"
   tools:context=".MainActivity">
   <ImageView
      android:id="@+id/iv"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:src="@drawable/image" />
</LinearLayout>

Java:

import androidx.appcompat.app.AppCompatActivity;
import android.os.*;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.widget.*;
public class MainActivity extends AppCompatActivity {
   private ScaleGestureDetector scaleGestureDetector;
   private float mScaleFactor = 1.0f;
   private ImageView imageView;  
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      imageView=findViewById(R.id.iv);
      scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());
   }
   @Override
   public boolean onTouchEvent(MotionEvent motionEvent) {
      scaleGestureDetector.onTouchEvent(motionEvent);
      return true;
   }
   private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
      @Override
      public boolean onScale(ScaleGestureDetector scaleGestureDetector) {
         mScaleFactor *= scaleGestureDetector.getScaleFactor();
         mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, 10.0f));
         imageView.setScaleX(mScaleFactor);
         imageView.setScaleY(mScaleFactor);
         return true;
      }
   }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-31
    • 2020-02-09
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 2016-09-17
    • 2013-01-14
    • 1970-01-01
    相关资源
    最近更新 更多