4

私は Android のアニメーションとジェスチャーに比較的慣れていません。

スライドさせたい画像が15枚あります。画面には一度に 1 つの画像しか表示されず、最初の画像で L->R をスライドすると、2 番目の画像が表示され、スライドショーのように表示されます。Android ギャラリーのチュートリアルを見ましたが、サムネイルを表示したくありません。私の理解は、ImageView を使用して画像を変更し続けることです。これは正しい方法ですか、それともより良い方法がありますか?

4

1 に答える 1

7

そうすれば、フリング効果は見られません。

ギャラリーでそれを行う 1 つの方法があります。

次のようにギャラリーを作成します。

<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/HorizontalGallery"
    android:gravity="center_vertical" android:spacing="2px"/>

getview では、次のことを行う必要があります。

public View getView(int position, View convertView, ViewGroup parent) {

ImageView i = new ImageView(_Context);

i.setImageResource(R.drawable.YourPicture);
i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));

//setting the scale:

int viewWidthtmp;
int viewHeighttmp;

if(getHeight() == 0)
{
    if(_horizGallery.getWidth() == 0){
        viewWidthtmp = _horizGallery.getWidth();
        viewHeighttmp = _horizGallery.getHeight();
    }
    else
    {
        viewWidthtmp = _screenWidth;
        viewHeighttmp = _screenHeight;
    }

//getting the size of the image.
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true; //returns null, but fills the out methods
bm = BitmapFactory.decodeResource(getResources(), R.drawable.YourPicture, o);
if(o.outHeight> viewHeight || o.outWidth> viewWidth) 
   {i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);}
else
   {i.setScaleType(ImageView.ScaleType.FIT_CENTER);}

//DO NOT ADD the line below
//i.setBackgroundResource(mGalleryItemBackground);

return i;

}

また、2 つのグローバル変数変数を宣言し、アクティビティの OnCreate で初期化する必要があります。

public class ScrollingGallery extends Activity
{
    private int _screenWidth;
    private int _screenHeight;


...

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scrollingallery);

        Display display = getWindowManager().getDefaultDisplay(); 
        _screenWidth = display.getWidth();
        _screenHeight = display.getHeight();

...

その後、タイマーでギャラリーをスクロールさせるだけです。

私が間違っていなければ、これは全ページのギャラリーで機能するはずです。コードは少し長く、書いたばかりなのでバグがあるかもしれません。

于 2011-04-01T16:31:30.433 に答える