Android的滑动抽屉打开上创建 [英] Android Sliding Drawer Open On Create

查看:132
本文介绍了Android的滑动抽屉打开上创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个滑块是开放的应用程序启动时。它会随着按钮和这样,当用户关闭它,就会有更多的按钮访问开放。带有滑动抽屉这可能吗?我会怎么添加到的onCreate()方法?

I want to have a slider that is open when the app starts. It will be open with buttons and such and when the user closes it, there will be more buttons to access. Is this possible with a sliding drawer? What would I add to the onCreate() method?

感谢

推荐答案

XML布局 - 在基本的LinearLayout:

XML Layout - In a basic 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>

和您的活动将是这样的:

And your Activity will looks like this:

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);
    }
}

这篇关于Android的滑动抽屉打开上创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆