Resize Imageview auf onDoubleTapEvent
Frage
Ich möchte eine ImageView
auf doubleTapEvent
ändern. Ein Codebeispiel wird sehr hilfreich sein.
Lösung
XML:
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myImage"
android:src="@drawable/myPicture"
android:layout_width="64sp"
android:layout_height="64sp"
/>
Java:
public class MyActivity extends Activity implements OnDoubleTapListener{
private ImageView img;
private static int NEW_WIDTH = 100;
private static int NEW_HEIGHT = 100;
@Override
public void onCreate(Bundle savedInstanceState){
setContentView(R.layout.myLayout);
this.img = findViewById(R.id.myImage);
img.setOnDoubleTapListener(this);
}
public boolean onDoubleTap(MotionEvent e){
this.img.setLayoutParams(new LayoutParams(NEW_WIDTH, NEW_HEIGHT));
}
So etwas wie dieses ...
Andere Tipps
Über Code funktioniert nicht geben Fehler auf img.setOnDoubleTapListener (dieser) Linie ... gibt solche Art von Fehlern „Das Verfahren setOnDoubleTapListener (this) wird die nicht definiert für den Typ Image“.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow