我是android新手。我正在尝试缩放一系列图像,因为我有10个可绘制的图像。我在主xml和2个按钮中有一个图像视图来更改图像。我从stackoverflow中的一个问题中获取了整个想法。问题是所有图像都在完美变化,但我不知道要缩放这些图像。我尝试了触摸图像视图代码,但仍未成功。 Plz帮助我。 主xml;
<?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="fill" android:orientation="vertical" android:weightSum="100" > <ImageView android:id="@+id/idImageViewPic" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="100" android:adjustViewBounds="true" android:background="#66FFFFFF" android:maxHeight="91dip" android:maxWidth="47dip" android:padding="10dip" android:src="@drawable/r0" /> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" > <Button android:id="@+id/bGeri" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Önceki" > </Button> <Button android:id="@+id/bIleri" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Sonraki" > </Button> </LinearLayout> </LinearLayout>
主要java。
package com.galerionsekiz; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; public class Main extends Activity { private ImageView hImageViewPic; private Button iButton, gButton; private int currentImage = 0; int[] images = { R.drawable.r1, R.drawable.r2, R.drawable.r3, R.drawable.r4, R.drawable.r5, R.drawable.r6, R.drawable.r7, R.drawable.r8, R.drawable.r9, R.drawable.r10 }; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); hImageViewPic = (ImageView)findViewById(R.id.idImageViewPic); iButton = (Button) findViewById(R.id.bIleri); gButton = (Button) findViewById(R.id.bGeri); //Just set one Click listener for the image iButton.setOnClickListener(iButtonChangeImageListener); gButton.setOnClickListener(gButtonChangeImageListener); } View.OnClickListener iButtonChangeImageListener = new OnClickListener() {public void onClick(View v) { //Increase Counter to move to next Image currentImage++; currentImage = currentImage % images.length; hImageViewPic.setImageResource(images[currentImage]); } }; View.OnClickListener gButtonChangeImageListener = new OnClickListener() { public void onClick(View v) { //Increase Counter to move to next Image currentImage--; currentImage = (currentImage + images.length) % images.length; hImageViewPic.setImageResource(images[currentImage]); }