【问题标题】:Clicking Children Item in Sliding Panel triggers parent first?单击滑动面板中的子项首先触发父项?
【发布时间】:2017-06-09 01:26:37
【问题描述】:

我正在使用滑动面板布局,并且我有一个浮动按钮。现在,当我单击按钮时,首先查看幻灯片,然后我必须再次单击按钮以执行操作。

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

看看这些图片 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();
            }
        }
    });
}

【问题讨论】:

  • 你能说得更具体些吗?
  • 我有一个滑动面板,其中有一个按钮。滑动面板最初是关闭的,用户可以看到一个按钮。因此,当我单击按钮时,滑动面板会打开,而不是执行在按钮的 onClick 中编写的操作。当我第二次点击按钮的 onClick 时,第一次点击时不起作用。所以问题是我的 onClick 按钮在第一次点击时不起作用@W4R10CK
  • 你希望代码同时运行和滑动打开吗?
  • 不,我只想在用户点击按钮时运行代码

标签: android android-sliding


【解决方案1】:

使用此代码:

<?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>

【讨论】:

  • 但是这里没有滑动面板。我尝试了视图不滑动的代码
  • 这意味着没有滑动面板?
  • 查看有问题的截图@W4R10CK
猜你喜欢
  • 1970-01-01
  • 2013-11-28
  • 1970-01-01
  • 2014-05-12
  • 1970-01-01
  • 2016-12-16
  • 2014-06-29
  • 2023-02-25
  • 2022-01-16
相关资源
最近更新 更多