Wie im titel. Ich möchte ein Raster von Bildern haben, das aus 2 Spalten besteht und jedes Bild muss die gleichen Dimensionen haben. Der Benutzer sollte in der Lage sein, auf jedes Bild zu klicken, um in den Vollbildmodus zu gelangen und dann Bilder von links nach rechts zu schieben (Bilder in voller Größe in diesem Modus). Bei weitem habe ich ein Raster aus anklickbaren Elementen erstellt, aber ohne die Funktionalität, sie zu verschieben. Hier ist mein Code:android gallery app mit gleitenden bildern
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.miki.androidtwo.MainActivity">
<GridView
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="2"
android:scrollbars="vertical"
android:gravity="center">
</GridView>
</RelativeLayout>
activity_full_image.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
tools:context="com.example.miki.androidtwo.FullImageActivity">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="I want to see other doggos" />
</RelativeLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridView = (GridView) findViewById(R.id.grid);
// Instance of ImageAdapter Class
gridView.setAdapter(new ImageAdapter(this));
/**
* On Click event for Single Gridview Item
* */
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// Sending image id to FullScreenActivity
Intent i = new Intent(getApplicationContext(), FullImageActivity.class);
// passing array index
i.putExtra("id", position);
startActivity(i);
}
});
}
}
Andere Klassen sind FullImageActivity und ImageAdapter; Sie sind ziemlich offensichtlich und einfach, also werde ich sie nicht veröffentlichen.
Wie kann ich diese Gleitbildfunktionalität implementieren?
Wie kann ich die Abmessungen von Bildern in einem Raster bestimmen, das unabhängig vom Gerät ist? Eigentlich glaube ich, ich habe es hart mit der Zeile codiert:
imageView.setLayoutParams (neue GridView.LayoutParams (480,402));
könnten Sie weitere Hinweise und Ideen zur Verwendung von ViewPager und PagerAdapter geben? sollte ich es zwischen imageView und Button in activity_full_image.xml und passendem Java-Code in der FullImageActivity-Klasse einfügen? – monterinio