点击放大Imageview [英] Enlarging an Imageview on click
问题描述
你好Stackoverflow朋友.我只是想知道是否有人可以帮助我.
Hello Stackoverflow friendo's. I'm just wondering if someone can assist me.
我创建了一个包含很多图像的应用程序,这些图像目前很小,但是我希望它们在单击后能够扩展.有什么办法吗? 我的应用程序包含大约50个xml,并且在类中相同.但是它可以容纳约100张图像,有没有简单的方法可以做到这一点?
I've created an app which holds a lot of images, the images are currently pretty small but I want them to expand once they're clicked. Is there any way of doing this? My app holds about 50 xml and the same in classes. But it holds about 100 images, is there any simple way to do this?
我的XML示例
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#808080"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="499dp"
android:orientation="vertical" >
<ImageView
android:id="@+id/Logo"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginLeft="255dp"
android:layout_marginTop="3dp"
android:src="@drawable/logov2" />
<TextView
android:id="@+id/title"
android:layout_width="210dp"
android:layout_height="84dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="-90dp"
android:gravity="center"
android:text="@string/seatedcablerows"
android:textColor="#FFFFFF"
android:textSize="32sp" />
<ImageView
android:id="@+id/blackline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:src="@drawable/blackline" />
<TextView
android:id="@+id/textView1"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:layout_marginLeft="15dp"
android:text="@string/startphase"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:textSize="16sp" />
<TextView
android:id="@+id/textView2"
android:layout_width="121dp"
android:layout_height="wrap_content"
android:layout_marginLeft="130dp"
android:layout_marginTop="-20dp"
android:text="@string/middlephase"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:textSize="16sp" />
<TextView
android:id="@+id/textView3"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_marginTop="-20dp"
android:layout_marginLeft="260dp"
android:text="@string/endphase"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:textSize="16sp" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="97dp"
android:layout_height="100dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:src="@drawable/seatedcablerowstart" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="97dp"
android:layout_height="100dp"
android:layout_marginLeft="130dp"
android:layout_marginTop="-100dp"
android:src="@drawable/seatedcablerowmid" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="97dp"
android:layout_height="100dp"
android:layout_marginLeft="245dp"
android:layout_marginTop="-100dp"
android:src="@drawable/seatedcablerowend" />
<ImageView
android:id="@+id/blackline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:src="@drawable/blackline" />
<TextView
android:id="@+id/seatedcablerowsdesc"
android:layout_width="match_parent"
android:layout_height="41dp"
android:layout_marginTop="3dp"
android:gravity="center"
android:text="@string/seatedcablerowsdesc"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:textSize="16sp" />
<TextView
android:id="@+id/seatedcablerowsperf"
android:layout_width="match_parent"
android:layout_height="238dp"
android:layout_marginTop="3dp"
android:gravity="center"
android:text="@string/seatedcablerowsperf"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF"
android:textSize="14sp" />
<TextView
android:id="@+id/seatedcablerowscaut"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_marginTop="3dp"
android:gravity="center"
android:text="@string/seatedcablerowscaut"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF"
android:textSize="14sp" />
<ImageView
android:id="@+id/blackline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:src="@drawable/blackline" />
<!--Set 1 starts here -->
<TextView
android:id="@+id/set1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set1"
android:textColor="#FFFF00"
android:textSize="25sp" />
<TextView
android:id="@+id/weight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-30dp"
android:layout_marginLeft="100dp"
android:text="@string/weight"
android:textColor="#FFFF00"
android:textSize="16sp"
/>
<TextView
android:id="@+id/repititions"
android:layout_width="116dp"
android:layout_height="wrap_content"
android:layout_marginLeft="240dp"
android:layout_marginTop="-20dp"
android:text="@string/repetitions"
android:textColor="#FFFF00"
android:textSize="16sp" />
<EditText
android:id="@+id/editText1"
android:layout_width="67dp"
android:layout_height="36dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:ems="10"
android:inputType="number"
>
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="67dp"
android:layout_height="36dp"
android:layout_marginLeft="240dp"
android:layout_marginTop="-37dp"
android:background="#FFFFFF"
android:ems="10"
android:inputType="number" >
</EditText>
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/blackline2" />
<!--Set 2 starts here -->
<TextView
android:id="@+id/set2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set2"
android:textColor="#FFFF00"
android:textSize="25sp"
/>
<TextView
android:id="@+id/weight1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-30dp"
android:layout_marginLeft="100dp"
android:text="@string/weight"
android:textColor="#FFFF00"
android:textSize="16sp"
/>
<TextView
android:id="@+id/repititions2"
android:layout_width="116dp"
android:layout_height="wrap_content"
android:layout_marginLeft="240dp"
android:layout_marginTop="-20dp"
android:text="@string/repetitions"
android:textColor="#FFFF00"
android:textSize="16sp" />
<EditText
android:id="@+id/editText3"
android:layout_width="67dp"
android:layout_height="36dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:ems="10"
android:inputType="number" >
</EditText>
<EditText
android:id="@+id/editText4"
android:layout_width="67dp"
android:layout_height="36dp"
android:layout_marginLeft="240dp"
android:layout_marginTop="-37dp"
android:background="#FFFFFF"
android:ems="10"
android:inputType="number" >
</EditText>
<ImageView
android:id="@+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/blackline2" />
<!--Set 3 starts here -->
<TextView
android:id="@+id/set3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set3"
android:textColor="#FFFF00"
android:textSize="25sp"
/>
<TextView
android:id="@+id/weight3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-30dp"
android:layout_marginLeft="100dp"
android:text="@string/weight"
android:textColor="#FFFF00"
android:textSize="16sp"
/>
<TextView
android:id="@+id/repititions3"
android:layout_width="116dp"
android:layout_height="wrap_content"
android:layout_marginLeft="240dp"
android:layout_marginTop="-20dp"
android:text="@string/repetitions"
android:textColor="#FFFF00"
android:textSize="16sp" />
<EditText
android:id="@+id/editText5"
android:layout_width="67dp"
android:layout_height="36dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:ems="10"
android:inputType="number" >
</EditText>
<EditText
android:id="@+id/editText6"
android:layout_width="67dp"
android:layout_height="36dp"
android:layout_marginLeft="240dp"
android:layout_marginTop="-37dp"
android:background="#FFFFFF"
android:ems="10"
android:inputType="number" >
</EditText>
<ImageView
android:id="@+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/blackline2" />
<!--Set 4 starts here -->
<TextView
android:id="@+id/set4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set4"
android:textColor="#FFFF00"
android:textSize="25sp"
/>
<TextView
android:id="@+id/weight4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-30dp"
android:layout_marginLeft="100dp"
android:text="@string/weight"
android:textColor="#FFFF00"
android:textSize="16sp"
/>
<TextView
android:id="@+id/repititions4"
android:layout_width="116dp"
android:layout_height="wrap_content"
android:layout_marginLeft="240dp"
android:layout_marginTop="-20dp"
android:text="@string/repetitions"
android:textColor="#FFFF00"
android:textSize="16sp" />
<EditText
android:id="@+id/editText7"
android:layout_width="67dp"
android:layout_height="36dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:ems="10"
android:inputType="number" >
</EditText>
<EditText
android:id="@+id/editText8"
android:layout_width="67dp"
android:layout_height="36dp"
android:layout_marginLeft="240dp"
android:layout_marginTop="-37dp"
android:background="#FFFFFF"
android:ems="10"
android:inputType="number" >
</EditText>
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="240dp"
android:layout_marginTop="35dp"
android:src="@drawable/savebutton"
android:background="@null" />
<ImageButton
android:id="@+id/QR"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-10dp"
android:layout_marginBottom="-60dp"
android:src="@drawable/qrscanner" />
</LinearLayout>
</ScrollView>
Java类:
package com.example.workplease;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import com.example.workplease_v2.R;
public class Seatedcablerows extends Activity {
ImageButton imagebutton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.seatedcablerows);
AddListenerOnButton();
}
public void AddListenerOnButton(){
final Context context = this;
imagebutton = (ImageButton) findViewById(R.id.QR);
imagebutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, Qrscanner.class);
startActivity(intent);
}
});
}
}
推荐答案
Google很好地解释了如何通过触摸放大视图.您也可以对图像视图使用相同的技术. 检查给定的链接以获取完整的示例代码.
Google has nicely explained How to enlarge view on a touch. You can use same technique for your image view also. Check the given link for full example code.
这篇关于点击放大Imageview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!