Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First define xml</p> <pre><code>&lt;? Xml version = “1.0″ encoding = “utf-8″?&gt; &lt;RelativeLayout xmlns: android = “http://schemas.android.com/apk/res/android” android: orientation = “vertical” the android: layout_width = “fill_parent The android: layout_height = “fill_parent The android: background = “55 million” &gt; &lt;ImageSwitcher / / this control with the Gallery often used, remember android: id = “@ + the id / in switcher ‘” the android: layout_width = “wrap_content The android: layout_height = “350dip The android: layout_alignParentLeft = “true” android: layout_alignParentRight = “true” /&gt; &lt; Gallery android: id = “@ + id / mygallery” the android: layout_width = “fill_parent The android: layout_height = “80dp” android: layout_alignParentBottom = “true” android: layout_alignParentLeft = “true” android: gravity = “center_vertical” android: spacing = “16dp” /&gt; &lt;/ RelativeLayout&gt; </code></pre> <p>Two. Activity in a custom display</p> <pre><code>package com.ldci.second.mypnone; import java.io.File; import java.util.ArrayList; import of java.util.List; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import the android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.view.View.OnClickListener; import android.view.animation.AnimationUtils; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageSwitcher; import android.widget.ImageView; import android.widget.Toast; import android.widget.ViewSwitcher; import android.widget.AdapterView.OnItemClickListener; import android.widget.Gallery.LayoutParams; public class BgPictureShowActivity extends Activity implements AdapterView.OnItemSelectedListener, ViewSwitcher.ViewFactory { the private List &lt;String&gt; the ImageList; private String [] list; private ImageSwitcher mSwitcher; public void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); / / / / Remove the status bar, and display their own program name / / GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, / / WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView (R.layout.pictureshow); The ImageList the getSD (); list = ImageList.toArray (new String [ImageList.size ()]); / * Set the Switcher * / mSwitcher = (ImageSwitcher) findViewById (R.id.switcher); mSwitcher.setFactory (this); / * Set the load Switcher mode * / mSwitcher.setInAnimation (AnimationUtils.loadAnimation (this, android.R.anim.fade_in)); / * Set output Switcher mode * / mSwitcher.setOutAnimation (AnimationUtils.loadAnimation (this, android.R.anim.fade_out)); mSwitcher.setOnClickListener (new OnClickListener () { public void onClick (View v) the { Toast.makeText (BgPictureShowActivity.this, “click”, Toast.LENGTH_SHORT). The show (); } }); Gallery g = (Gallery) findViewById (R.id.mygallery); / * Add several ImageAdapter to and set to the Gallery object * / g.setAdapter (new ImageAdapter (this, getSD ())); g.setOnItemSelectedListener (this); / * Set a itemclickListener event * / g.setOnItemClickListener (new OnItemClickListener () { public void the onItemClick (AdapterView, which &lt;?&gt; parent, View v, int position, long id) { Toast.makeText (BgPictureShowActivity.this, “dianjiale”, Toast.LENGTH_SHORT). Show (); } }); } private List &lt;String&gt; getSD () { / * Set the current path * / The the List &lt;String&gt; it = the new ArrayList &lt;String&gt; (); File f = new File (“/ sdcard /”); File [] files = f.listFiles (); / * All the files stored in the ArrayList * / for (int i = 0; i &lt;files.length; i + +) { The File the file = files [i]; if (getImageFile (file.getPath ())) it.add (file.getPath ()); } return it; } private boolean getImageFile (String fName) { a boolean the re; / * Get the extension * / String end = fName.substring (fName.lastIndexOf (“.”) +1, fName.length ()). toLowerCase (); / * Decided by the type of extension The MimeType * / if (end.equals (“jpg”) | | end.equals (“gif”) | | end.equals (“png”) | | End.equals (“jpeg”) | | end.equals (“bmp”)) { re = true; } else { re = false; } return the re; } / * To rewrite BaseAdapter custom one ImageAdapter class * / public class ImageAdapter the extends BaseAdapter, { / * Declare variables * / int mGalleryItemBackground; private Context mContext; private the List &lt;String&gt; of lis; / * ImageAdapter, constructed character * / the public ImageAdapter (Context c, the List &lt;String&gt; li) { mContext = c; of lis = li; / * Res / values ​​/ attrs.xml &lt;declare-styleable&gt; defined * Gallery attribute * / TypedArray a = obtainStyledAttributes (R.styleable.Gallery); / * Obtain attribute Gallery Index id * / mGalleryItemBackground = a.getResourceId ( R.styleable.Gallery_android_galleryItemBackground, 0); / * Let the object styleable properties can be used repeatedly * / a.recycle (); } / * A few set to rewrite the getCount, the number of returned images * / public int the getCount () { return lis.size (); } / * Must override the method getItem, returns the position * / Public Object getItem (int position) { the return position; } / * Must be rewritten getItemId pass and position * / public long getItemId (int position) { the return position; } / * A few set to rewrite the method getView pass and View objects * / public View getView (int position, View convertView, Of ViewGroup that the parent) { / * Generate the ImageView object * / ImageView i = new ImageView (mContext); / * Set the picture to imageView object * / Bitmap bm = BitmapFactory.decodeFile (lis. get (position). toString ()); i.setImageBitmap (bm); / * Reset the image width and height * / i.setScaleType (ImageView.ScaleType.FIT_XY); / * Reset the Layout of the width and height * / i.setLayoutParams (new Gallery.LayoutParams (136, 88)); / * Set the Gallery background images * / i.setBackgroundResource (mGalleryItemBackground); / * Pass back to imageView object * / return i; } } public void onItemSelected (AdapterView &lt;?&gt; parent, View view, int position, long id) { The string photoURL = list [position]; Log.i (“A”, String.valueOf (position)); mSwitcher.setImageURI (Uri.parse (photoURL)); } public void onNothingSelected (AdapterView &lt;?&gt; parent) { / / TODO Auto-generated method the stub } public View makeView () { ImageView i = new ImageView (this); i.setBackgroundColor (0xFF000000); i.setScaleType (ImageView.ScaleType.FIT_CENTER); i.setLayoutParams (new ImageSwitcher.LayoutParams ( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); return i; } } </code></pre> <p>This code is very long, to see will certainly be a headache plus DAN pain, but to hold on the MARS God repeatedly warned we in this industry is characterized to be patient. There is a very important thing, in the values ​​file folder, create an xml inside the book:</p> <pre><code>&lt;? Xml version = “1.0″ encoding = “utf-8″?&gt; &lt;resources&gt; &lt;declare-styleable name=”Gallery”&gt; &lt;attr name=”android:galleryItemBackground” /&gt; &lt;/ Declare-styleable &lt;/ Resources&gt; </code></pre> <p><a href="http://developer.aiwgame.com/gallery-show-an-image-from-android-sd-card.html" rel="nofollow">http://developer.aiwgame.com/gallery-show-an-image-from-android-sd-card.html</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload