创建一个在Android中向上和向外滑动的面板

时间:2014-11-19 12:04:04

标签: android slideup

我需要一些指导。我需要制作一个自定义视图,触摸并将屏幕幻灯片拖出屏幕。我尝试过这个很酷的库:here但这依赖于2个布局。滑出的那个和之后剩下的那个。我现在拥有的是越野车和丑陋。

public class DemoActivity extends Activity {

private SlidingUpPanelLayout mLayout;
private RelativeLayout layout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_demo);

    layout = (RelativeLayout) findViewById(R.id.panel);
    final int defaulttop = layout.getTop();
    final int defaultbottom = layout.getBottom();

    RelativeLayout dragView = (RelativeLayout) findViewById(R.id.dragView);

    mLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
    mLayout.setDragView(dragView);
    mLayout.setPanelSlideListener(new PanelSlideListener() {

        @Override
        public void onPanelSlide(View panel, float slideOffset) {
        }

        @Override
        public void onPanelExpanded(View panel) {
            System.out.println("panel expanded");
        }

        @Override
        public void onPanelCollapsed(View panel) {
            System.out.println("panel collapsed");
        }

        @Override
        public void onPanelAnchored(View panel) {
            System.out.println("anchored");
        }

        @Override
        public void onPanelHidden(View panel) {
            System.out.println("panel is hidden now");
        }
    });

}

@Override
public void onBackPressed() {
    if (mLayout != null && mLayout.isPanelExpanded()) {
        mLayout.collapsePanel();
    } else {
        super.onBackPressed();
    }
}

}

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DemoActivity" >

    <com.sothree.slidinguppanel.SlidingUpPanelLayout
        xmlns:sothree="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:gravity="bottom"
        sothree:dragView="@+id/dragView"
        sothree:panelHeight="60dp"
        sothree:paralaxOffset="60dp"
        sothree:shadowHeight="0dp" >

        <RelativeLayout
            android:id="@+id/panel"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/unt"
            android:orientation="vertical" >

            <Button
                android:id="@+id/button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_gravity="center"
                android:text="Sleep" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/dragView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:clickable="true"
            android:focusable="false" >
        </RelativeLayout>
    </com.sothree.slidinguppanel.SlidingUpPanelLayout>

</RelativeLayout>

它向上滑动但背面留下白色背景。如果我触摸屏幕然后滑动。所以,我需要一条新路。有人有类似的东西吗?我需要一个提示,而不是代码。感谢。

2 个答案:

答案 0 :(得分:0)

我使用过你在这里提到的图书馆,对我来说很好。您可能没有设置拖动视图/布局

使用mSlidingPanelLayout.setDragView(YourLayout)设置可以拖动的布局

答案 1 :(得分:0)

我之前做过类似的事,但是有一个按钮。 我在Animation移动时使用OnTouchListener类完成了它。虽然在使用它时必须小心并控制布局的X和Y值。