私は約20枚の画像を持っています。各画像と 1 つの ImageView のボタンを作成しました。ボタンをクリックすると、対応する画像が ImageView に設定され、ズームとドラッグが有効になります。次に、他のボタンをクリックして次/前の画像に移動すると置き換えます。
ここで、ボタンを削除し、クイック スライドを垂直方向に実装して置き換える必要があります。下から上にすばやくスライドすると、次の画像に移動します。次に、上から下にすばやくスライドして、前の画像に移動します。また、最初の画像または最後の画像に到達した場合も無効にします。
画像を扱うImageViewのListを考えています。次に、List で現在の ImageView のインデックスを維持することにより、クイック スライド機能を実装します。
Android 2.1 を使用してクイック スライド ページングを実装する方法に関する正しい方向性に関するガイダンスは、非常に高く評価されています。
UPDATES1ボタン(次へ、前へ)を使用してImageSwitcherスライドを上下に正常に使用しました。私の次の問題は、Next&Prev に移動するためのクイック スライドで実装する方法です。現在のコードを追加します。
注: TouchImageView クラスは、ズームとドラッグをサポートしています。ゆっくりスライドすると、画像はその方向にドラッグされますが、すばやく上下にスライドすると、次と前の画像にそれぞれ移動したいと思います。
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageSwitcher android:id="@+id/switcher1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_weight="0"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button android:id="@+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"/>
<Button android:id="@+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prev"/>
</LinearLayout>
</LinearLayout>
アクティビティ: (注: TouchImageView はRecipeBook060 Zoom and Drag から取得しました Extended ImageView、Slide Images のアイデアはSlide Imageから取得しました)
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageSwitcher;
import android.widget.ViewSwitcher.ViewFactory;
public class ImageSwticherActivity extends Activity
implements ViewFactory {
Integer[] imageIDs = { R.drawable.image_one, R.drawable.image_two,
R.drawable.image_three };
private ImageSwitcher imageSwitcher;
private Button nextButton;
private Button previousButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Animation in = AnimationUtils.loadAnimation(this,
android.R.anim.slide_in_left);
final Animation out = AnimationUtils.loadAnimation(this,
android.R.anim.slide_out_right);
imageSwitcher = (ImageSwitcher) findViewById(R.id.switcher1);
imageSwitcher.setFactory(this);
imageSwitcher.setInAnimation(in);
imageSwitcher.setOutAnimation(out);
imageSwitcher.setImageResource(imageIDs[0]);
nextButton = (Button) findViewById(R.id.next);
nextButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Animation out= AnimationUtils.loadAnimation(ImageSwticherActivity.this, R.anim.slide_out_bottom);
Animation in= AnimationUtils.loadAnimation(ImageSwticherActivity.this, R.anim.slide_in_top);
imageSwitcher.setInAnimation(in);
imageSwitcher.setOutAnimation(out);
imageSwitcher.setImageResource(imageIDs[1]);
}
});
previousButton = (Button) findViewById(R.id.previous);
previousButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Animation out= AnimationUtils.loadAnimation(ImageSwticherActivity.this, R.anim.slide_out_top);
Animation in= AnimationUtils.loadAnimation(ImageSwticherActivity.this, R.anim.slide_in_bottom);
imageSwitcher.setInAnimation(in);
imageSwitcher.setOutAnimation(out);
imageSwitcher.setImageResource(imageIDs[0]);
}
});
}
@Override
public View makeView() {
//ImageView imageView = new ImageView(ImageSwticherActivity.this);
TouchImageView imageView = new TouchImageView(ImageSwticherActivity.this);
imageView.setBackgroundColor(0xFF000000);
//imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setLayoutParams(new ImageSwitcher.LayoutParams(
ImageSwitcher.LayoutParams.FILL_PARENT, ImageSwitcher.LayoutParams.FILL_PARENT));
return imageView;
}
}
slide_in_bottom.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="-50%p" android:toYDelta="0"
android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
slide_in_top.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="50%p" android:toYDelta="0"
android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
slide_out_bottom.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0" android:toYDelta="-50%p"
android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
slide_out_top.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0" android:toYDelta="50%p"
android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="@android:integer/config_mediumAnimTime" />
</set>