簡體   English   中英

Android滑動抽屜在創建時打開

[英]Android Sliding Drawer Open On Create

我想要一個在應用啟動時打開的滑塊。 它將通過按鈕等打開,當用戶關閉它時,將有更多按鈕可供訪問。 滑動抽屜可以嗎? 我會在onCreate()方法中添加什么?

謝謝

XML布局-在基本的LinearLayout中:

  <SlidingDrawer
    android:id="@+id/slide"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:content="@+id/content"
    android:handle="@+id/handle"
    android:orientation="vertical"
    android:scrollbars="vertical" >

    <LinearLayout
        android:id="@id/handle"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/btn"
        android:gravity="center"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/handleImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_tray_expand" />

        <Button
            android:id="@+id/handleButton"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@drawable/btn"
            android:text="Up me" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/content"
        android:paddingTop="2dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#013E53"
        android:gravity="center"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/tv_commentDisplay"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:paddingLeft="10dp"
            android:textSize="20dp" />
    </LinearLayout>
</SlidingDrawer>

您的活動將如下所示:

public class Home extends Activity implements OnDrawerScrollListener
{

private ImageView               handleImage;
private Button                  handleButton;
private SlidingDrawer           slide;
    private TextView                tv_commentDisplay;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);

            tv_commentDisplay = (TextView)this.findViewById(R.id.tv_commentDisplay);
    handleImage = (ImageView)this.findViewById(R.id.handleImage);
    handleButton = (Button)this.findViewById(R.id.handleButton);
    slide = (SlidingDrawer)this.findViewById(R.id.slide);

    slide.open(); // not sure
    slide.setOnDrawerScrollListener(this);

    handleButton = ((Button)this.findViewById(R.id.handleButton));

    tv_commentDisplay.setText("Hello World");
}

@Override
public void onScrollEnded() {
}

@Override
public void onScrollStarted() {
    if (slide.isOpened())
        handleImage.setImageResource(R.drawable.ic_tray_collapse);
    else {
        handleImage.setImageResource(R.drawable.ic_tray_expand);
    }
}

onCreate()使用open() ,它將立即打開抽屜。

您可以在此處查看完整的API

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM