2012-02-26 68 views
1

我正在使用另一個列表視圖來代替嘗試執行示例應用中給出的3d轉換的圖像視圖。但列表視圖出現在屏幕右側留在原地及文字inverted.my列表顯示如下:如何使用列表視圖代替android中的圖像視圖3d轉換

enter image description here

我的代碼是:

public class EventListActivity extends ListActivity { 

private ListView lv1, lv2; 
private ViewGroup mContainer; 
private ArrayList<ArrayAdapter<String>> arr; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.eventlist); 
    arr = new ArrayList<ArrayAdapter<String>>(); 
    String[] eventlist = getResources().getStringArray(R.array.eventlist); 
    String[] eventlist1 = getResources().getStringArray(R.array.techc); 
    String[] eventlist2 = getResources().getStringArray(R.array.presc); 
    String[] eventlist3 = getResources().getStringArray(R.array.roboc); 
    String[] eventlist4 = getResources().getStringArray(R.array.managec); 
    String[] eventlist5 = getResources().getStringArray(R.array.literaryc); 
    String[] eventlist6 = getResources().getStringArray(R.array.creationc); 
    String[] eventlist7 = getResources().getStringArray(R.array.gamingc); 
    ArrayAdapter<String> a1 = new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, eventlist1); 
    ArrayAdapter<String> a2 = new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, eventlist2); 
    ArrayAdapter<String> a3 = new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, eventlist3); 
    ArrayAdapter<String> a4 = new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, eventlist4); 
    ArrayAdapter<String> a5 = new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, eventlist5); 
    ArrayAdapter<String> a6 = new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, eventlist6); 
    ArrayAdapter<String> a7 = new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, eventlist7); 
    arr.add(a1); 
    arr.add(a3); 
    arr.add(a2); 

    arr.add(a4); 
    arr.add(a5); 
    arr.add(a6); 
    arr.add(a7); 
    final ArrayAdapter<String> a = new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, eventlist); 
    lv1 = getListView(); 
    lv2 = (ListView) findViewById(R.id.list2); 
    mContainer = (ViewGroup) findViewById(R.id.container); 
    lv1.setAdapter(a); 
    lv2.setClickable(true); 
    lv2.setFocusable(true); 
    mContainer 
      .setPersistentDrawingCache(ViewGroup.PERSISTENT_ANIMATION_CACHE); 
    lv1.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
       long arg3) { 
      // TODO Auto-generated method stub 
      lv2.setAdapter(arr.get(arg2)); 

      applyRotation(arg2, 0, 90); 

     } 
    }); 

} 

protected void applyRotation(int position, int start, int end) { 
    // TODO Auto-generated method stub 
    final float centerX = mContainer.getWidth()/2.0f; 
    final float centerY = mContainer.getHeight()/2.0f; 

    // Create a new 3D rotation with the supplied parameter 
    // The animation listener is used to trigger the next animation 
    final Rotate3dAnimation rotation = new Rotate3dAnimation(start, end, 
      centerX, centerY, 310.0f, true); 
    rotation.setDuration(500); 
    rotation.setFillAfter(true); 
    rotation.setInterpolator(new AccelerateInterpolator()); 
    rotation.setAnimationListener(new DisplayNextView(position)); 

    mContainer.startAnimation(rotation); 
} 

private final class DisplayNextView implements Animation.AnimationListener { 
    private final int mPosition; 

    private DisplayNextView(int position) { 
     mPosition = position; 
    } 

    public void onAnimationStart(Animation animation) { 
    } 

    public void onAnimationEnd(Animation animation) { 
     mContainer.post(new SwapViews(mPosition)); 
    } 

    public void onAnimationRepeat(Animation animation) { 
    } 
} 

/** 
* This class is responsible for swapping the views and start the second 
* half of the animation. 
*/ 
private final class SwapViews implements Runnable { 
    private final int mPosition; 

    public SwapViews(int position) { 
     mPosition = position; 
    } 

    public void run() { 
     final float centerX = mContainer.getWidth()/2.0f; 
     final float centerY = mContainer.getHeight()/2.0f; 
     Rotate3dAnimation rotation; 

     if (mPosition > -1) { 
      lv1.setVisibility(View.GONE); 
      lv2.setVisibility(View.VISIBLE); 
      lv2.requestFocus(); 

      rotation = new Rotate3dAnimation(90, 180, centerX, centerY, 
        310.0f, false); 
     } else { 
      lv2.setVisibility(View.GONE); 
      lv1.setVisibility(View.VISIBLE); 
      lv1.requestFocus(); 

      rotation = new Rotate3dAnimation(90, 0, centerX, centerY, 
        310.0f, false); 
     } 

     rotation.setDuration(500); 
     rotation.setFillAfter(true); 
     rotation.setInterpolator(new DecelerateInterpolator()); 

     mContainer.startAnimation(rotation); 
    } 
}} 

我的XML代碼`

<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layoutAnimation="@anim/layout_bottom_to_top_slide" 
    android:persistentDrawingCache="animation|scrolling" /> 

<ListView 
    android:id="@+id/list2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:scaleType="fitCenter" 
    android:visibility="gone" /> 

`

我怎樣才能得到正確的位置列表視圖?

+0

ü可以把eventlist.xml代碼 – Sumant 2012-02-26 16:30:01

+0

這些列表視圖是。我是在發佈完整的XML代碼 – Arihant 2012-02-26 16:37:20

回答

1

你可能它旋轉到180度,這會導致倒退列表

你需要的是旋轉360度。雖然這會導致更多的「spinnings」,你可以通過以下方式僞造:

將列表改爲90度。當列表變成90度時,我們看不到它,您可以用新的替換您的列表。 然後在AnimationListener.onAnimationEnd()你剛纔動畫列表中的一個更多的時間從270到360

Rotate3dAnimation rotation = new Rotate3dAnimation(270, 360, centerX, centerY, 60.0f, false); 

不聽它的盡頭。

完全onAnimationEnd:

public void onAnimationEnd(Animation animation) {  
    // RENDER YOUR NEW LIST HERE 

    final float centerX = mContainer.getWidth()/2.0f; 
     final float centerY = mContainer.getHeight()/2.0f; 

     Rotate3dAnimation rotation = new Rotate3dAnimation(270, 360, centerX, centerY, 60.0f, false); 

    rotation.setDuration(500); 
    rotation.setFillAfter(true); 
    rotation.setInterpolator(new AccelerateInterpolator()); 
    mContainer.startAnimation(rotation); 
} 
+0

它工作有難度的FrameLayout完全知道感謝你的努力 – Arihant 2012-02-27 09:41:09