单击滑动面板中的子项目首先触发父项?

时间:2017-01-24 09:49:40

标签: android android-sliding

我正在使用滑动面板布局,因为我有一个浮动按钮。现在,当我点击按钮时,视图首先滑动,然后我必须再次单击按钮才能执行操作。

我想在没有父视图滑动的情况下单击即可执行操作。

看看这些图片 Look at 1 images look at this 这是我的

XML

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

<android.support.v4.widget.SlidingPaneLayout           
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:id="@+id/Sliding"
android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:id="@+id/leftSide"
        android:background="#ef3"
        >

        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/contact"
            android:background="@drawable/bg_key"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true" />
    </RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:background="@color/colorAccent"
    android:id="@+id/rightSide"
    android:layout_marginLeft="170dp"
    android:layout_height="match_parent">

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fabSize="mini"
        android:focusable="false"
        app:srcCompat="@drawable/ic_menu_camera"
        android:id="@+id/call"
        android:layout_alignParentTop="true"
        android:layout_alignStart="@+id/message" />

</RelativeLayout>
</android.support.v4.widget.SlidingPaneLayout>

这是我的java代码

SlidingPaneLayout sp;
 @Override
protected void onCreate(Bundle savedInstanceState)
{
    context = this;
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    call = (FloatingActionButton) findViewById(R.id.call);

    sp = (SlidingPaneLayout) findViewById(R.id.Sliding);
    assert sp != null;
    sp.setPanelSlideListener(this);
    sp.setSliderFadeColor(Color.TRANSPARENT);
    sp.openPane();
    mList = new ArrayList<Contacts>();

    call.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            Log.e("CALL","CALL");
            try
            {
                if(number.isEmpty())
                {
                    Toast.makeText(context,"Please select contact first",Toast.LENGTH_SHORT).show();
                }
                else
                {
                    calling();
                    number=null;
                }

            }
            catch (Exception e)
            {
                e.printStackTrace();
                Toast.makeText(context,"This is not the valid contact",Toast.LENGTH_SHORT).show();
            }
        }
    });
}

1 个答案:

答案 0 :(得分:0)

使用此代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.v4.widget.SlidingPaneLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:id="@+id/Sliding"
android:layout_height="match_parent">

<RelativeLayout
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:id="@+id/leftSide"
    android:background="#ef3"
    >

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/contact"
        android:background="@drawable/bg_key"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v4.widget.SlidingPaneLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:background="@color/colorAccent"
    android:id="@+id/rightSide"
    android:layout_marginLeft="170dp"
    android:layout_height="match_parent">

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fabSize="mini"
        android:focusable="false"
        app:srcCompat="@drawable/ic_menu_camera"
        android:id="@+id/call"
        android:layout_alignParentTop="true" />
</RelativeLayout>
</RelativeLayout>