Ich fand viele Fragen zum Bildwechsel in Bildansicht mit einem anderen Bild, aber ich habe ein anderes Problem.So ändern Sie die xml-Quelle von SVG-Bild in einer Bildansicht
Ich habe zwei SVG-Bilder im Xml-Format in einem drückbaren Ordner. Ich möchte zwischen den Bildern beim Klicken auf Bildansicht wechseln. Wenn zum Beispiel image a.xml da ist, dann wird beim Klicken darauf image b.xml angezeigt, dazu muss ich die aktuelle xml image source von imageview holen und auf den anderen setzen.
Wie geht das?
MainActivity.java:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.imageView);
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(v == iv){
if(/* How to check current current source of imagevie here */ ){
/* How to set new xml svg source to imagevie here */
}
}
}
});
}
}
xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
tools:context="com.abcd.MainActivity">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:srcCompat="@android:drawable/alert_dark_frame"
android:src="@drawable/a"
android:layout_centerHorizontal="true"
android:id="@+id/imageView"
android:layout_alignParentTop="true" />
</FrameLayout>
drawable folder containing two svg sources