`
mysfzj_web
  • 浏览: 14560 次
  • 性别: Icon_minigender_1
  • 来自: 成都
最近访客 更多访客>>
社区版块
存档分类
最新评论

项目中ViewFlipper 的使用

 
阅读更多

  效果展示




 
点击右下角的btn


 
同一个activity里切换到另一个界面


具体实现:

主要java代码
public class FlipperActivity extends Activity{
      private ViewFlipper flipper = null;
      private ImageButton button = null;
      private boolean flag=false;
      
      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.flipper);
            
            flipper = (ViewFlipper) findViewById(R.id.flipper);
            button = (ImageButton) findViewById(R.id.back);
            
            button.setOnClickListener(new View.OnClickListener() {


                  public void onClick(View arg0) {


                        if (flag) {
                              //跳到下一个flipper
                              flipper.showNext();
                              //flipper切换的效果
                              new AnimationUtils();
                              flipper.setInAnimation(AnimationUtils.loadAnimation(
                                          FlipperActivity.this, R.anim.push_left_in));
                              new AnimationUtils();
                              flipper.setOutAnimation(AnimationUtils.loadAnimation(
                                          FlipperActivity.this, R.anim.push_left_out));
                              button
                                          .setBackgroundResource(R.drawable.pdp_info_button);
                        } else {
                              //跳到下一个flipper
                              flipper.showNext();
                              //flipper切换的效果
                              new AnimationUtils();
                              flipper.setInAnimation(AnimationUtils.loadAnimation(
                                          FlipperActivity.this, R.anim.push_right_in));
                              new AnimationUtils();
                              flipper.setOutAnimation(AnimationUtils.loadAnimation(
                                          FlipperActivity.this, R.anim.push_right_out));
                              button
                                          .setBackgroundResource(R.drawable.pdp_info_button_back);
                        }
                        flag = !flag;


                  }


            });
      }
}


 
XML文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/whitetextcolor"
    >
   
<ViewFlipper android:id="@+id/flipper"
            android:layout_height="120dp" android:layout_width="wrap_content">
            <!-- 第一个flipper-->
            <RelativeLayout android:layout_height="wrap_content"
                  android:layout_width="fill_parent" android:id="@+id/relativeLayout1">
                  <ImageView android:id="@+id/imageView1"       android:src="@drawable/md_hometabicon"
                        android:layout_width="wrap_content" android:layout_height="wrap_content"
                        android:layout_marginLeft="40dip" android:layout_marginTop="80dip" />
                  <TextView android:id="@+id/price" android:layout_width="wrap_content"
                        android:layout_height="wrap_content" android:text="$5.00"
                        android:textColor="@color/yellowtextcolor"
                        android:layout_marginLeft="200dip" android:layout_marginTop="80dip" />
            </RelativeLayout>


            <!-- 第二个flipper-->
            <RelativeLayout android:layout_height="wrap_content"
                  android:layout_width="fill_parent" android:id="@+id/relativeLayout1">


                  <TextView android:id="@+id/price" android:layout_width="wrap_content"
                        android:layout_height="wrap_content" android:text="这是一座房子,面朝大海,春暖花开"
                        android:layout_marginLeft="40dip" android:layout_marginTop="80dip"
                        android:textColor="@color/yellowtextcolor" />
            </RelativeLayout>
      </ViewFlipper>
   <ImageButton android:id="@+id/back" android:background="@drawable/pdp_info_button"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:layout_gravity="bottom|right" />
</LinearLayout>
 
  • 大小: 5.8 KB
  • 大小: 7 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics