2013-02-09 33 views
0

我已經使用Flipper.we通常在flipper標籤中添加布局。如下在fllipperview子視圖中添加不起作用

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

在我的計劃有三個活動,我想在鰭顯示(這應該flipp此起彼伏。)

每個活動seperately執行一些任務。

當我將該佈局文件添加到鰭標籤。如下圖所示,

(這是我的主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; 
} 
} 

現在在我的代碼腳蹼工作正常,但活動,我想在Flipper中顯示不工作(Activites不工作,意味着listview不加載數據,按鈕,textview可見但不支持任何事件)。

有誰能告訴我該怎麼辦..?

+0

ü可以發佈您的代碼對包括標籤只是追加問題 – Pratik 2013-02-09 10:45:18

+0

@Pratik:我添加的代碼。 screenxyz.xml,screenabc.xml和activity_main.xml是我的佈局文件。 – Jayshree 2013-02-09 11:14:36

+0

@Guddu你是什麼意思下「不工作」,他們不顯示在屏幕上或什麼? – Evos 2013-02-09 11:31:17

回答

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> 
+0

然後我應該在我的代碼中使用此id ...在java文件中 – Jayshree 2013-02-09 11:49:38

+0

yap,即findViewById(R.id.xyzview); – FatDog47 2013-02-09 11:56:23

+0

我已經爲每個佈局編寫了獨立的java文件。 我應該寫在一個Java文件中的所有代碼.. 然後我如何使用該佈局的子視圖... 好的,謝謝先生,先生,我試試這種方式... 你給了我一種思考方式。 謝謝先生 – Jayshree 2013-02-09 12:13:54

相關問題