从下往上滑动片段

时间:2014-08-21 14:00:36

标签: android slidingdrawer

我试图创建这个滑动面板,一旦我收到推送通知就会显示出来,但我似乎无法做到正确。

我希望面板本身是交互式的,所以我希望它是一个不同的片段。

我的主要活动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>

为了尝试,我设置了这个简单的片段并尝试听取它的textView onClickListener:

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上一样。

1 个答案:

答案 0 :(得分:0)

确保您在活动XML中引用了面板类,或者为了实际使用该类而膨胀了ID /面板。

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

相关问题