2010-08-12 31 views
5

Tôi đang cố gắng sử dụng ViewFlipper để thêm hoạt ảnh giữa các chế độ xem, như trong hướng dẫn sau về chủ đề. Tuy nhiên, nó dường như không muốn làm việc. Nó sẽ thay đổi các trang, nhưng tôi sẽ không có hoạt ảnh - ngay cả khi tôi thêm một sự chậm trễ lớn vào push_left_in.Không có hoạt ảnh với ViewFlipper?

Dưới đây là onCreate của tôi:


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     viewFlipper = (ViewFlipper)findViewById(R.id.flipper); 
     viewFlipper.setAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in)); 
     mapView = (MapView)findViewById(R.id.mapView); 
     mapView.setBuiltInZoomControls(true); 
    } 

push_left_in xuất phát từ mẫu của Google. Đây là hành động kích hoạt:


    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle item selection 
     switch (item.getItemId()) { 
     case R.id.button_map: 
      viewFlipper.setDisplayedChild(0); 
      return true; 
     case R.id.button_conditions_general: 
      viewFlipper.setDisplayedChild(1); 
      return true; 
(etc) 

Và bố trí của tôi:

 

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout android:id="@+id/mainlayout" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       xmlns:android="http://schemas.android.com/apk/res/android"> 

    <ViewFlipper android:id="@+id/flipper" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 

    <view class="com.google.android.maps.MapView" 
      android:id="@+id/mapView" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:clickable="true" 
      android:apiKey="MY_API_KEY" 
      /> 

    <TableLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="#ffffff" 
       android:stretchColumns="1" 
       > 
     <TableRow> 
     <TextView android:id="@+id/field1" 
        android:layout_column="1"   
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:textColor="#000000" 
        android:textStyle="bold" 
        android:textSize="18px" 
        android:text="@string/field1" 
        > 
     </TextView> 
     <EditText android:text="100" 
        android:id="@+id/field2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"> 
     </EditText> 
     <TextView android:id="@+id/field3" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:textColor="#000000" 
        android:textStyle="bold" 
        android:textSize="18px" 
        android:text="%" 
        > 
     </TextView> 
     </TableRow> 
    </TableLayout> 

    </ViewFlipper> 
</LinearLayout> 

 

Suy nghĩ?

+0

Không có gì nhảy ra khỏi tôi, mặc dù tôi đã không sử dụng một MapView trong một ViewFlipper trước. FWIW, đây là một dự án mẫu hiển thị hoạt ảnh với ViewFlipper, trong trường hợp nó giúp: http://github.com/commonsguy/cw-android/tree/master/Fancy/Flipper2/ – CommonsWare

+0

@CommonsBạn đã xóa hoạt ảnh khỏi đó thí dụ. Có vấn đề gì thế? – ohhorob

+0

@ohhorob: Xin lỗi về điều đó. Chỉ đơn giản là làm ví dụ về cuốn sách, vì tôi không giải quyết các hoạt ảnh ở bất kỳ nơi nào khác trong cuốn sách cụ thể đó. – CommonsWare

Trả lời

11

Thử đặt hoạt ảnh của bạn trong tệp xml thay thế.

<ViewFlipper android:id="@+id/flipper" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:inAnimation="@anim/push_left_in"> 
+0

Điều đó đã làm được điều đó - cảm ơn! Một lưu ý cho những người khác với vấn đề đó: Tôi đã không thể nhìn thấy các sửa chữa làm việc ngay lập tức thông qua giả lập, do tỷ lệ khung hình thấp giả lập - nhưng một sự chậm trễ thêm cho tôi nhìn thấy nó. Một lần nữa, cảm ơn, shwiz! – Karen

0

Bạn cần đặt riêng hoạt ảnh trong và ngoài. Bạn có thể làm điều đó trong XML:

<ViewFlipper 
    android:id="@+id/view_flipper" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:inAnimation="@anim/in_from_right" 
    android:outAnimation="@anim/out_to_left"> 

hoặc trong mã:

viewFlipper.setInAnimation(getActivity(), R.anim.in_from_right); 
viewFlipper.setOutAnimation(getActivity(), R.anim.out_to_left); 
Các vấn đề liên quan