简体   繁体   English

Android平台:如何显示可滚动,可缩放的图像

[英]Android Platform: How do i display scrollable, zoomable image

I have a set of 8 images, i want to show them one by one in sequence. 我有一组8个图像,我想按顺序逐个显示它们。 Next image will appear once a button is clicked. 单击一个按钮后,将出现下一个图像。

I am able to load my image in imageview. 我可以在imageview中加载我的图像。 1. I cannot find how to change the image on button click 2. How to make changes in program so that image is scrobbable & zoomable. 1.我无法找到如何在按钮单击2上更改图像。如何在程序中进行更改以使图像可以进行可缩放和缩放。

enter code here
<?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"
  android:layout_weight="1">
  <ImageView
  android:id="@+id/imageview1"
  android:gravity="center_horizontal"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_weight="1"
  android:src="@drawable/img1"      
  android:adjustViewBounds="true"
  android:keepScreenOn="true" 
  android:scrollbarStyle="outsideOverlay"
  android:scrollbars="horizontal" android:scaleType="fitXY"/>
  <Button      
  android:layout_height="wrap_content"
  android:layout_width="fill_parent"
  android:id="@+id/button1"
  android:text="Next"/>
</LinearLayout>
  1. In the onClickLister of your button call: 在按钮调用的onClickLister中:
    YourImageView.setImageBitmap(YourBitmap);

  2. Check out this link. 看看这个链接。 A great tutorial with basics about multi-touch gestures on Android, it also got an example of how to move around and pinch-zoom an image. 这是一本关于Android上多点触控手势基础知识的精彩教程,它还提供了如何移动和捏合缩放图像的示例。

For the zoom ImageView, see this post. 对于缩放ImageView,请参阅文章。 As far as how to change images when a button is clicked, I would suggest you read how to add a button click listener from here . 至于如何在单击按钮时更改图像,我建议您阅读如何从此处添加按钮单击侦听器。 Google "android button onclick example" and you will find lots of examples. 谷歌“android按钮onclick示例”,你会发现很多例子。 If you are still unsure how to change the Image upon clicking a button, you should check out the Android Developers Guide , it has lots of useful information like handling events, UI, etc... 如果您仍然不确定如何在单击按钮时更改图像,则应查看Android开发人员指南 ,它包含许多有用的信息,如处理事件,UI等...

Also they have some great tutorials here . 此外,他们有一些伟大的教程在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM