2013-04-16 6 views
-2

У меня возникли проблемы с тем, как сделать автоматическое слайд-шоу с помощью ImageSwitchers и Gallery. Единственное, что я понимаю, это анимация между переходами фотографий, когда вы выбираете их из галереи, например, как они исчезают или перемещаются слева направо.Есть ли способ сделать автоматическое слайд-шоу с помощью графических чатов и галерей?

EDIT

Моя цель пытается сделать слайд-шоу так же, как при создании галереи и выберите каждые снимки затем использовать imageswitcher для отображения выбранного изображения на нижнем макете. Как раз на этот раз, вместо того, чтобы на самом деле щелкнуть, я хочу, чтобы фотографии перемещались автоматически (следующий за последним), например, на Powerpoints и с таймером.

Полный список: package project.CaseStudy;

public class Slideshow extends Activity implements ViewFactory { 
    //---the images to display--- 
    Integer[] imageIDs = { 
      R.drawable.pic1, 
      R.drawable.pic2, 
      R.drawable.pic3, 
      R.drawable.pic4, 
      R.drawable.pic5, 
      R.drawable.pic6, 
      R.drawable.pic7 
    }; 

    TextView legend; 
    TextView imageID; 

    CheckBox repeat; 
    CheckBox image; 
    CheckBox text; 

    public int picture; 
    public int pictureCurrentlySelected; 

    private ImageSwitcher imageSwitcher; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.slideshow); 

     legend = (TextView) findViewById(R.id.legend); 
     imageID = (TextView) findViewById(R.id.imagenum); 

     repeat = (CheckBox) findViewById(R.id.repeat); 
     image = (CheckBox) findViewById(R.id.number); 
     text = (CheckBox) findViewById(R.id.text); 

     //text.setEnabled(true); 
     //image.setEnabled(true); 
     //repeat.setEnabled(true); 


     imageSwitcher = (ImageSwitcher) findViewById(R.id.switcher1); 
     imageSwitcher.setFactory(this); 


     imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, 
       android.R.anim.fade_in)); 
     imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, 
       android.R.anim.fade_out)); 


     /*imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, 
       android.R.anim.slide_in_left)); 
     imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, 
       android.R.anim.slide_out_right)); 

     */ 
     pictureCurrentlySelected = -1; 
     Gallery gallery = (Gallery) findViewById(R.id.gallery1); 
     gallery.setAdapter(new ImageAdapter(this)); 
     gallery.setOnItemClickListener(new OnItemClickListener() 
     { 
      public void onItemClick(AdapterView<?> parent, 
      View v, int position, long id) 
      { 
       imageSwitcher.setImageResource(imageIDs[position]); 
       picture = position; 
       pictureCurrentlySelected = picture; 
       check(); 
      } 
     }); 
    } 

    public View makeView() 
    { 
     ImageView imageView = new ImageView(this); 
     imageView.setBackgroundColor(0xFF000000); 
     imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); 
     imageView.setLayoutParams(new 
       ImageSwitcher.LayoutParams(
         LayoutParams.FILL_PARENT, 
         LayoutParams.FILL_PARENT)); 
     return imageView; 
    } 

    public class ImageAdapter extends BaseAdapter 
    { 
     private Context context; 
     private int itemBackground; 

     public ImageAdapter(Context c) 
     { 
      context = c; 

      //---setting the style--- 
      TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); 
      itemBackground = a.getResourceId(
        R.styleable.Gallery1_android_galleryItemBackground, 0); 
      a.recycle(); 
     } 

     //---returns the number of images--- 
     public int getCount() 
     { 
      return imageIDs.length; 
     } 

     //---returns the item--- 
     public Object getItem(int position) 
     { 
      return position; 
     } 

     //---returns the ID of an item--- 
     public long getItemId(int position) 
     { 
      return position; 
     } 

     //---returns an ImageView view--- 
     public View getView(int position, View convertView, ViewGroup parent) 
     { 
      ImageView imageView = new ImageView(context); 

      imageView.setImageResource(imageIDs[position]); 
      imageView.setScaleType(ImageView.ScaleType.FIT_XY); 
      imageView.setLayoutParams(new Gallery.LayoutParams(150, 120)); 
      imageView.setBackgroundResource(itemBackground); 

      return imageView; 
     } 
    } 

    public void onCheckBoxClickListener(View v) 
    { 
     boolean checked = ((CheckBox) v).isChecked(); 

     switch(v.getId()){ 

     case R.id.repeat: 
      /*if(checked) 
      { 
       return; 
      }*/ 
      break; 

     case R.id.text: 
      if(!checked) 
       legend.setText(""); 
      else 
      { 
       if(pictureCurrentlySelected == -1) 
       { 
        legend.setText(""); 
       } 
       else 
        check(); 
      } 

      break; 

     case R.id.number: 
      if(!checked) 
       imageID.setText(""); 
      else 
      { 
       if(pictureCurrentlySelected == -1) 
       { 
        legend.setText(""); 
       } 
       else 
        check(); 
      } 

      break; 

     } 
    } 

    private void check() 
    { 
     if(text.isChecked()) 
     { 
      if(picture == 0) 
       legend.setText("This is San Fransisco's Bridge. A beautiful Sight!"); 
      else if(picture == 1) 
       legend.setText("This is the train used to pick up the bitches around town."); 
      else if(picture == 2) 
       legend.setText("The outstanding lake of San Fransisco"); 
      else if(picture == 3) 
       legend.setText("A beautiful view of the city!"); 
      else if(picture == 4) 
       legend.setText("Beauty at its limit."); 
      else if(picture == 5) 
       legend.setText("Town at sunset."); 
      else 
       legend.setText("Bridge during within a beautiful sight."); 

     } 
     /*else 
      legend.setText("");*/ 

     if(image.isChecked()) 
     { 
      if(picture == 0) 
       imageID.setText("Image number 1"); 
      else if(picture == 1) 
       imageID.setText("Image number 2"); 
      else if(picture == 2) 
       imageID.setText("Image number 3"); 
      else if(picture == 3) 
       imageID.setText("Image number 4"); 
      else if(picture == 4) 
       imageID.setText("Image number 5"); 
      else if(picture == 5) 
       imageID.setText("Image number 6"); 
      else 
       imageID.setText("Image number 7"); 

     } 
     //else 
      //legend.setText(""); 

     if(repeat.isChecked()) 
     { 
     } 
     //else; 

    } 

} 

Игнорировать последние два метода, если это слишком сложно, чтобы понять, я просто набрасывать свою программу и в конечном итоге устранить избыточность позже.

Вот 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:orientation="vertical" > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Images of San Francisco" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <CheckBox 
      android:id="@+id/repeat" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:onClick="onCheckBoxClickListener" 
      android:text="Repeat" /> 

     <CheckBox 
      android:id="@+id/number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:onClick="onCheckBoxClickListener" 
      android:text="Image ID" /> 

     <CheckBox 
      android:id="@+id/text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:onClick="onCheckBoxClickListener" 
      android:text="Text" /> 

    </LinearLayout> 

    <Gallery 
     android:id="@+id/gallery1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.50" > 

     <ImageSwitcher 
      android:id="@+id/switcher1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 
     </ImageSwitcher> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Image number: " /> 

     <TextView 
      android:id="@+id/imagenum" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/legend" 
      android:layout_width="match_parent" 
      android:layout_height="57dp" 
      android:text="" /> 

    </LinearLayout> 

</LinearLayout> 
+0

«Есть ли способ ...» - это * ужасный вопрос. Не могли бы вы более подробно объяснить, каков ваш вопрос на самом деле? Вы показали два куска кода с небольшим объяснением проблемы. –

+0

Там вы идете. Я хочу сказать, что я не могу придумать автоматическое слайд-шоу. – Morpheglus

ответ

0

Я не знаю точно, что вы пытаетесь достичь, но лучше (читай: простой) способ я знаю, чтобы создать небольшой слайд-шоу просто поместите ваши изображения и/или текстовые элементы в макет фрейма. Затем в вашем коде вы должны использовать оператор switch, который устанавливает видимость каждого изображения.

например. случай 0:

image1.setVisibility (View.VISIBLE);

image2.setVisibility (View.INVISIBLE);

И т.д. ....

+0

Человек Я редактировал свой вопрос, надеюсь, вы понимаете. Ваш код не то, что я ищу. – Morpheglus

+0

Добро пожаловать! –