android– 在Framelayout中相互重叠的两个布局之间滑动

android– 在Framelayout中相互重叠的两个布局之间滑动,第1张

概述我想在两个线性布局之间滑动,这些布局包裹在框架布局中.同时,只有一个线性布局可见.我正在使用按钮来显示/隐藏它们.我想在其中实现滑动功能.我试过了ViewFliper但手指滑动没有用.是否可以使用ViewPager执行此 *** 作?布局XML是<?xmlversion="1.0"encoding="utf-8"?><FrameL

我想在两个线性布局之间滑动,这些布局包裹在框架布局中.同时,只有一个线性布局可见.我正在使用按钮来显示/隐藏它们.我想在其中实现滑动功能.我试过了VIEwFliper但手指滑动没有用.是否可以使用VIEwPager执行此 *** 作?

布局XML是

<?xml version="1.0" enCoding="utf-8"?>
    <FrameLayout        androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent"        androID:background="#00000000" >        <linearLayout            androID:ID="@+ID/laytopUp"            androID:layout_wIDth="fill_parent"            androID:layout_height="fill_parent"            androID:background="@drawable/yellowspace"            androID:gravity="center_vertical|center_horizontal"            androID:orIEntation="vertical"            androID:padding="25dp"            androID:visibility="visible" >            <TextVIEw                androID:ID="@+ID/textVIEw1"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="3dp"                androID:text="XXX"                androID:textcolor="#000000" />            <Spinner                androID:ID="@+ID/spntopupOperator"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="3dp" />            <TextVIEw                androID:ID="@+ID/textVIEw2"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="3dp"                androID:text="XXX"                androID:textcolor="#000000" />            <linearLayout                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="10dp"                androID:gravity="center_vertical|center_horizontal" >                <TextVIEw                    androID:ID="@+ID/textVIEw3"                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:text="XXX"                    androID:textcolor="#000000" />                <EditText                    androID:ID="@+ID/ettopUpCode"                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:ems="3"                    androID:hint="Code"                    androID:inputType="number"                    androID:maxLength="3" >                    <requestFocus />                </EditText>                <EditText                    androID:ID="@+ID/ettopUpNumber"                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:ems="7"                    androID:hint="Number"                    androID:inputType="number"                    androID:maxLength="7"                    androID:shadowcolor="#000000" />            </linearLayout>            <TextVIEw                androID:ID="@+ID/textVIEw4"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="3dp"                androID:text="XXX"                androID:textcolor="#000000" />            <Spinner                androID:ID="@+ID/spntopupAmount"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="3dp" />            <linearLayout                androID:ID="@+ID/layConv"                androID:layout_wIDth="fill_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="3dp"                androID:gravity="center_vertical|center_horizontal"                androID:orIEntation="horizontal" >                <TextVIEw                    androID:ID="@+ID/tvConvertedamount"                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:gravity="center_vertical|center_horizontal"                    androID:text="XXX "                    androID:textcolor="#000000" />                <Progressbar                    androID:ID="@+ID/pbConversion"                                        androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:visibility="gone" />            </linearLayout>            <Imagebutton                androID:ID="@+ID/btopUpSend"                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:layout_margintop="3dp"                androID:background="@drawable/sendrechbotton" />        </linearLayout>        <linearLayout            androID:ID="@+ID/layScratchCard"            androID:layout_wIDth="fill_parent"            androID:layout_height="fill_parent"            androID:background="@drawable/yellowspace"            androID:gravity="center_vertical|center_horizontal"            androID:orIEntation="vertical"            androID:padding="25dp"            androID:visibility="gone" >            <TextVIEw                androID:ID="@+ID/textVIEw6"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:text="XXXX"                androID:textcolor="#000000" />            <Spinner                androID:ID="@+ID/spnRechargeOperator"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content" />            <TextVIEw                androID:ID="@+ID/textVIEw7"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:text="XXX"                androID:textcolor="#000000" />            <EditText                androID:ID="@+ID/etRechargeEmail"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:ems="10"                androID:hint="Email"                androID:inputType="textEmailAddress" />            <TextVIEw                androID:ID="@+ID/textVIEw8"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:text="XXXX"                androID:textcolor="#000000" />            <Spinner                androID:ID="@+ID/spnRechargeAmount"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content" />            <Imagebutton                androID:ID="@+ID/bSendCard"                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:background="@drawable/sendcardbotton" />        </linearLayout>    </FrameLayout></linearLayout>

解决方法:

解:
您需要使用GestureDetector在linearLayout上进行滑动时收到通知

请查看GestureDetector以供参考.

截至目前,我已经在你的代码中应用了swipe,但是我没有你的drawables所以我刚刚使用了mine.rest的东西已经准备好了.所以只使用你的xml文件而不是我的.

例:

MainActivity.java

package com.mehuljoisar.swipe;import androID.app.Activity;import androID.content.Intent;import androID.os.Bundle;import androID.vIEw.GestureDetector;import androID.vIEw.MotionEvent;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OntouchListener;import androID.vIEw.animation.Animation;import androID.vIEw.animation.AnimationUtils;import androID.Widget.FrameLayout;import androID.Widget.ImageVIEw;import androID.Widget.linearLayout;import androID.Widget.Toast;public class MainActivity extends Activity {private GestureDetector gesturedetector = null;private Intent i;private FrameLayout flContainer;private linearLayout ivLayer1,ivLayer2;@OverrIDepublic voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.acti);    flContainer = (FrameLayout) findVIEwByID(R.ID.flContainer);    ivLayer1 = (linearLayout)findVIEwByID(R.ID.laytopUp);    ivLayer2 = (linearLayout)findVIEwByID(R.ID.layScratchCard);    gesturedetector = new GestureDetector(new MyGestureListener());    flContainer.setontouchListener(new OntouchListener() {        @OverrIDe        public boolean ontouch(VIEw v, MotionEvent event) {            gesturedetector.ontouchEvent(event);            return true;        }    });}public boolean dispatchtouchEvent(MotionEvent ev) {    super.dispatchtouchEvent(ev);    return gesturedetector.ontouchEvent(ev);}class MyGestureListener extends GestureDetector.SimpleOnGestureListener {    private static final int SWIPE_MIN_disTANCE = 20;    private static final int SWIPE_MAX_OFF_PATH = 100;    private static final int SWIPE_THRESHolD_VELociTY = 100;    @OverrIDe    public boolean onFling(MotionEvent e1, MotionEvent e2, float veLocityX,    float veLocityY) {        float dX = e2.getX() - e1.getX();        float dY = e1.getY() - e2.getY();        if (Math.abs(dY) < SWIPE_MAX_OFF_PATH &&        Math.abs(veLocityX) >= SWIPE_THRESHolD_VELociTY &&        Math.abs(dX) >= SWIPE_MIN_disTANCE) {            if (dX > 0) {                Toast.makeText(getApplicationContext(), "Right Swipe",                        Toast.LENGTH_SHORT).show();                //Now Set your animation                if(ivLayer2.getVisibility()==VIEw.GONE)                {                    Animation fadeInAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.slIDe_right_in);                    ivLayer2.startAnimation(fadeInAnimation);                    ivLayer2.setVisibility(VIEw.VISIBLE);                }            } else {                Toast.makeText(getApplicationContext(), "left Swipe",                        Toast.LENGTH_SHORT).show();                if(ivLayer2.getVisibility()==VIEw.VISIBLE)                {                    Animation fadeInAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.slIDe_left_out);                    ivLayer2.startAnimation(fadeInAnimation);                    ivLayer2.setVisibility(VIEw.GONE);                }            }            return true;        } else if (Math.abs(dX) < SWIPE_MAX_OFF_PATH &&        Math.abs(veLocityY) >= SWIPE_THRESHolD_VELociTY &&        Math.abs(dY) >= SWIPE_MIN_disTANCE) {            if (dY > 0) {                Toast.makeText(getApplicationContext(), "Up Swipe",                        Toast.LENGTH_SHORT).show();            } else {                Toast.makeText(getApplicationContext(), "Down Swipe",                        Toast.LENGTH_SHORT).show();            }            return true;        }        return false;    }}}

acti.xml

    <?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:ID="@+ID/linear"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="vertical" ><FrameLayout    androID:ID="@+ID/flContainer"    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:layout_gravity="center_horizontal"    androID:background="@androID:color/black" >        <linearLayout            androID:ID="@+ID/laytopUp"            androID:layout_wIDth="fill_parent"            androID:layout_height="fill_parent"            androID:background="@androID:color/darker_gray"            androID:gravity="center_vertical|center_horizontal"            androID:orIEntation="vertical"            androID:padding="25dp"            androID:visibility="visible" >            <TextVIEw                androID:ID="@+ID/textVIEw1"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="3dp"                androID:text="XXX"                androID:textcolor="#000000" />            <Spinner                androID:ID="@+ID/spntopupOperator"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="3dp" />            <TextVIEw                androID:ID="@+ID/textVIEw2"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="3dp"                androID:text="XXX"                androID:textcolor="#000000" />            <linearLayout                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="10dp"                androID:gravity="center_vertical|center_horizontal" >                <TextVIEw                    androID:ID="@+ID/textVIEw3"                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:text="XXX"                    androID:textcolor="#000000" />                <EditText                    androID:ID="@+ID/ettopUpCode"                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:ems="3"                    androID:hint="Code"                    androID:inputType="number"                    androID:maxLength="3" >                    <requestFocus />                </EditText>                <EditText                    androID:ID="@+ID/ettopUpNumber"                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:ems="7"                    androID:hint="Number"                    androID:inputType="number"                    androID:maxLength="7"                    androID:shadowcolor="#000000" />            </linearLayout>            <TextVIEw                androID:ID="@+ID/textVIEw4"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="3dp"                androID:text="XXX"                androID:textcolor="#000000" />            <Spinner                androID:ID="@+ID/spntopupAmount"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="3dp" />            <linearLayout                androID:ID="@+ID/layConv"                androID:layout_wIDth="fill_parent"                androID:layout_height="wrap_content"                androID:layout_margintop="3dp"                androID:gravity="center_vertical|center_horizontal"                androID:orIEntation="horizontal" >                <TextVIEw                    androID:ID="@+ID/tvConvertedamount"                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:gravity="center_vertical|center_horizontal"                    androID:text="XXX "                    androID:textcolor="#000000" />                <Progressbar                    androID:ID="@+ID/pbConversion"                                        androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:visibility="gone" />            </linearLayout>            <Imagebutton                androID:ID="@+ID/btopUpSend"                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:layout_margintop="3dp"                androID:background="@drawable/icon" />        </linearLayout>        <linearLayout            androID:ID="@+ID/layScratchCard"            androID:layout_wIDth="fill_parent"            androID:layout_height="fill_parent"            androID:background="@drawable/icon"            androID:gravity="center_vertical|center_horizontal"            androID:orIEntation="vertical"            androID:padding="25dp"            androID:visibility="gone" >            <TextVIEw                androID:ID="@+ID/textVIEw6"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:text="XXXX"                androID:textcolor="#000000" />            <Spinner                androID:ID="@+ID/spnRechargeOperator"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content" />            <TextVIEw                androID:ID="@+ID/textVIEw7"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:text="XXX"                androID:textcolor="#000000" />            <EditText                androID:ID="@+ID/etRechargeEmail"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:ems="10"                androID:hint="Email"                androID:inputType="textEmailAddress" />            <TextVIEw                androID:ID="@+ID/textVIEw8"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:text="XXXX"                androID:textcolor="#000000" />            <Spinner                androID:ID="@+ID/spnRechargeAmount"                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content" />            <Imagebutton                androID:ID="@+ID/bSendCard"                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:background="@drawable/icon" />        </linearLayout></FrameLayout><!--     <TextVIEw        androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content"        androID:text="abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd" /> --></linearLayout>

slIDe_left_out.xml

    <set xmlns:androID="http://schemas.androID.com/apk/res/androID">    <translate androID:fromXDelta="0" androID:toXDelta="-100%p" androID:duration="800"/></set>

slIDe_right_in.xml

<set xmlns:androID="http://schemas.androID.com/apk/res/androID">    <translate androID:fromXDelta="-100%p" androID:toXDelta="0" androID:duration="800"/></set>

我希望它会有所帮助!!

总结

以上是内存溢出为你收集整理的android – 在Framelayout中相互重叠的两个布局之间滑动全部内容,希望文章能够帮你解决android – 在Framelayout中相互重叠的两个布局之间滑动所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1106578.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存