0

Flipper を使用しました。通常、flipper タグにレイアウトを追加します。以下のように

<flipper>
   <LinearLayout1>
   <LinearLayout2>
</flipper>

私のプログラムには、フリッパーで表示したいアクティビティが 3 つあります (これは次々とフリッピングする必要があります)。

各アクティビティは、いくつかのタスクを個別に実行します。

そのレイアウトファイルをフリッパータグに追加すると。以下に示すように、

(これは私のメインの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="horizontal" >

<ViewFlipper
    android:id="@+id/ViewFlipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff" >

    <include
        android:id="@+id/screenxyzf"
        layout="@layout/screenxyz" />

    <include
        android:id="@+id/screenabcf"
        layout="@layout/screenabc" />

    <include
        android:id="@+id/activity_mainf"
        layout="@layout/activity_main" />
</ViewFlipper>

</LinearLayout>

// 私の Java コード...

package com.example.exampledemo3;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ViewFlipper;

public class Swipe extends Activity {

ViewFlipper flipper;
float lastX;
View.OnTouchListener gestureListener;
LinearLayout chapterMain,chapterAbc,chapterXyz;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.swipe);
    flipper = (ViewFlipper) findViewById(R.id.ViewFlipper);
    /*chapterMain=(LinearLayout) findViewById(R.id.activity_mainf);
    chapterAbc=(LinearLayout) findViewById(R.id.screenabcf);
    chapterXyz=(LinearLayout) findViewById(R.id.screenxyzf);*/

    flipper.setDisplayedChild(R.id.activity_mainf);
    flipper.setDisplayedChild(R.id.screenabcf);
    flipper.setDisplayedChild(R.id.screenxyzf);     


}

public boolean onTouchEvent(MotionEvent touchevent) {

    switch (touchevent.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        lastX = touchevent.getX();
        break;
    }
    case MotionEvent.ACTION_UP: {
        float currentX = touchevent.getX();
        if (lastX < currentX) {
            if (flipper.getDisplayedChild() == 0)
                break;
            flipper.setInAnimation(this, R.anim.in_from_left);
            flipper.setOutAnimation(this, R.anim.out_to_right);
            flipper.showNext();
        }
        if (lastX > currentX) {
            if (flipper.getDisplayedChild() == 1)
                break;
            flipper.setInAnimation(this, R.anim.in_from_right);
            flipper.setOutAnimation(this, R.anim.out_to_left);
            flipper.showPrevious();
        }
        break;
    }
    }
    return false;
}
 }

現在、私のコードではフリッパーは正常に動作していますが、フリッパーに表示したいアクティビティが動作していません (アクティビティが動作していない、リストビューがデータをロードしていない、ボタン、テキストビューが表示されているが、イベントをサポートしていない)。

誰が私に何をすべきか教えてもらえますか..?

4

1 に答える 1

0
  1. 「screenxyz.xml」および「screenabc.xml」ファイルを作成し、その内容を入力しましたか?
  2. android:idインクルードごとに設定する必要があります。そうしないと、それらは役に立たなくなります。
  3. ViewFlipper 以外のビューがない場合は、LinearLayout を安全に削除できます。

これをチェックしてください:

<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/ViewFlipper"
    android:background="#ffffff" >

<include layout="@layout/screenxyz"
    android:id="@+id/xyzView" />
<include layout="@layout/activity_main" 
    android:id="@+id/mainView" />
<include layout="@layout/screenabc" 
    android:id="@+id/abcView" />

</ViewFlipper>
于 2013-02-09T11:31:34.093 に答える