【问题标题】:Sliding fragment from bottom - up自下而上的滑动片段
【发布时间】:2014-08-21 14:00:35
【问题描述】:

我正在尝试创建这个滑动面板,它会在我收到推送通知后自动显示,但我似乎无法正确处理。

我希望面板本身具有交互性,因此我希望它是一个不同的片段。

我的主要活动 xml 如下所示:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <!-- main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:id="@+id/panel"
            android:layout_width="match_parent"
            android:layout_gravity="bottom"
            android:layout_height="wrap_content"></FrameLayout>
    </FrameLayout>

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:background="@drawable/gradientbg"
        android:choiceMode="singleChoice"
        android:divider="#1c1c1c"
        android:dividerHeight="1dp" />
    <!--  android:background="#111" -->


</android.support.v4.widget.DrawerLayout>

只是为了尝试,我设置了这个简单的片段并尝试在点击Listener的textView上听:

public class Panel extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.panel, container, false);
        view.bringToFront();

        //view.animate().translationYBy(100f).setDuration(1300);

        TextView text = (TextView) view.findViewById(R.id.textView);
        text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                view.animate().translationYBy(-300f).setDuration(1300).start();
                Toast.makeText(getActivity(), "fasf", Toast.LENGTH_SHORT).show();
            }
        });

        return view;
    }
}

不幸的是,textView 没有响应任何触摸事件。就像片段不在 z-index 上一样。

【问题讨论】:

  • 先检查TextView是否设置为可点击?
  • 是的,我已将其添加到 xml 中。还是不行
  • 还加了onTouchListener,还是不行

标签: android slidingdrawer


【解决方案1】:

确保您在 Activity XML 中引用面板类或膨胀 id/panel 以便您实际使用该类。

此外,在修复此问题后,请考虑使面板符合一种方式,即drawer_layout 可以调用openDrawer/closeDrawer 而不是使用当前动画。

【讨论】:

  • 我正在添加这个片段:ft.replace(R.id.panel, new Panel(), "panel");
  • 我可以在屏幕上看到片段,但它没有响应任何触摸事件
  • 然后采取解构的方法。删除您视图中可能干扰触摸的所有内容,然后再次测试。这将确定是否是片段/窗口或视图中其他对象的错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-06
相关资源
最近更新 更多