ViewFlipper滑动出现空白页

使用ViewFlipper做轮播,滑到最后一页时出现空白页,继续滑动才是应该出现在最后一页之后的第一页,(循环轮播时最后一页和第一页之间出现了空白页),下面是我的轮播实现代码

XML布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/activity_gatt_detail"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
    <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:fitsSystemWindows="true"
            android:titleTextColor="@android:color/white"
            android:background="#009688"
            app:navigationIcon="@drawable/back"
            app:title="设备名称"
            app:titleMarginStart="50dp"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
    </android.support.v7.widget.Toolbar>
    <!--获取设备版本号,测点编号,工作模式,预警参数,电池电量并显示-->
    <TextView android:id="@+id/show_Properties"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"/>
    <LinearLayout android:layout_width="match_parent"
                  android:layout_weight="0.5"
                  android:background="@color/white"
                  android:layout_height="match_parent"
                  android:orientation="horizontal">
        <android.support.v7.widget.RecyclerView
                android:id="@+id/lv_msg"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:visibility="gone"/>
        <RelativeLayout
                android:id="@+id/rl_write"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:visibility="gone"/>
        <TextView
                android:id="@+id/tv_properties"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#00796B"
                android:paddingBottom="5dp"
                android:paddingLeft="16dp"
                android:paddingRight="16dp"
                android:paddingTop="5dp"
                android:textColor="@android:color/white"
                android:visibility="gone"/>
        <!--send发送按钮-->
        <Button
                android:id="@+id/btn_send"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:layout_alignParentRight="true"
                android:background="@drawable/selector_btn_options"
                android:text="send"
                android:textColor="@android:color/white"
                android:visibility="gone"/>
        <EditText
                android:id="@+id/et_write"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@id/btn_send"
                android:hint="input content"
                android:maxLines="2"
                android:textCursorDrawable="@android:color/white"
                android:textSize="18sp"
                android:visibility="gone"/>
        <RelativeLayout
                android:id="@+id/rl_content"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/white">
            <!--操作文本信息-->
            <RelativeLayout
                    android:id="@+id/rl_bottom"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:background="#009688"
                    android:paddingLeft="2dp"
                    android:paddingRight="2dp"
                    android:visibility="gone"/>
            <View
                    android:id="@+id/view_filter"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@color/colorPrimary"
                    android:visibility="gone"/>
        </RelativeLayout>
    </LinearLayout>

    <ViewFlipper
            android:layout_weight="0.5"
            android:layout_marginTop="0dp"
            android:id="@+id/ViewFlipper"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

        <RelativeLayout android:id="@+id/RelativeLayout1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@drawable/one">
            <Button android:text="当前数据"
                    android:layout_marginTop="50dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/curData_button"
                    android:layout_alignParentTop="true"
                    android:layout_alignStart="@+id/btn_clearData"/>

            <Button android:layout_width="wrap_content"
                    android:text="数据条数"
                    android:id="@+id/btn_getStorageDataNum"
                    android:layout_height="wrap_content"
                    android:layout_alignTop="@+id/curData_button"
                    android:layout_alignStart="@+id/btn_allData"/>

            <Button android:layout_width="wrap_content"
                    android:text="清除数据"
                    android:id="@+id/btn_clearData"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_marginStart="70dp"
                    android:layout_alignTop="@+id/btn_allData"/>

            <Button android:layout_width="wrap_content"
                    android:text="数据采集"
                    android:id="@+id/btn_allData"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_marginEnd="70dp"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="50dp"/>
        </RelativeLayout>
        <RelativeLayout android:id="@+id/RelativeLayout2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@drawable/two">
            <Button
                    android:text="设置系统时间"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/btn_setTime"
                    android:layout_alignStart="@+id/setwarn_button"
                    android:layout_alignTop="@+id/restart_button"/>

            <Button android:layout_width="wrap_content"
                    android:text="设置预警参数"
                    android:id="@+id/setwarn_button"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_marginEnd="70dp"
                    android:layout_alignTop="@+id/setmode_button"/>

            <Button android:layout_width="wrap_content"
                    android:layout_marginTop="50dp"
                    android:text="设置工作模式"
                    android:id="@+id/setmode_button"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_alignStart="@+id/restart_button"/>

            <Button android:layout_width="wrap_content"
                    android:text="重启采集设备"
                    android:id="@+id/restart_button"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_marginStart="70dp"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="50dp"/>
        </RelativeLayout>
        <RelativeLayout android:id="@+id/RelativeLayout3"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@drawable/three">
            <Button android:layout_width="wrap_content"
                    android:text="设置测点编号"
                    android:id="@+id/setnum_button"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_marginStart="70dp"
                    android:layout_alignParentTop="true"
                    android:layout_marginTop="50dp"/>
            <Button android:layout_width="wrap_content"
                    android:text="获取系统时间"
                    android:id="@+id/btn_getTime"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_marginEnd="70dp"
                    android:layout_alignTop="@+id/setnum_button"
                    android:visibility="visible"/>
        </RelativeLayout>
    </ViewFlipper>
    <Button
            android:id="@+id/btn_option"
            android:text="启动"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="3dp"
            android:background="@drawable/selector_btn_options"
            android:textSize="18sp"/>
    <!--<Button android:layout_width="match_parent"-->
    <!--android:layout_height="wrap_content"-->
    <!--android:backgroundTint="@color/blue"-->
    <!--android:id="@+id/btn_startEnd"/>-->
</LinearLayout>

下面是Activity中的滑动功能实现:

public class GattDetailActivity extends MyBaseActivity implements OnGestureListener {
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gatt_detail);
detector = new GestureDetector(this);
//        View view= this.getLayoutInflater().inflate(R.layout.activity_gatt_detail, null);//加上不能滑动
        flipper = (ViewFlipper)/*view.*/findViewById(R.id.ViewFlipper);
        flipper.addView(addRelativeLayoutView(R.id.RelativeLayout1));
        flipper.addView(addRelativeLayoutView(R.id.RelativeLayout2));

}

public View addRelativeLayoutView(int id) {
    RelativeLayout relativeLayout = new RelativeLayout(this);
    relativeLayout.setId(id);
    return relativeLayout;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    // TODO Auto-generated method stubreturn this.detector.onTouchEvent(event);
    return detector.onTouchEvent(event);
}

@Override
public boolean onDown(MotionEvent e) {
    // TODO Auto-generated method stubreturn false;
    return false;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    if (e1.getX() - e2.getX() > 120) {
        this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in));
        this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out));
        this.flipper.showNext();
        return true;
    } else if (e1.getX() - e2.getX() < -120) {
        this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_in));
        this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_out));
        this.flipper.showPrevious();
        return true;
    }
    return true;
}

@Override
public void onLongPress(MotionEvent e) {
    // TODO Auto-generated method stub
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    // TODO Auto-generated method stubreturn false;
    return false;
}

@Override
public void onShowPress(MotionEvent e) {
    // TODO Auto-generated method stub
}

@Override
public boolean onSingleTapUp(MotionEvent e) {
    // TODO Auto-generated method stubreturn false;
    return false;
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值