gpt4 book ai didi

java - Android 滑动抽屉在创建时打开

转载 作者:行者123 更新时间:2023-11-29 08:09:21 25 4
gpt4 key购买 nike

我想要一个在应用程序启动时打开的 slider 。它将通过按钮等打开,当用户关闭它时,将有更多按钮可供访问。这可以用滑动抽屉吗?我应该向 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>

您的 Activity 将如下所示:

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

关于java - Android 滑动抽屉在创建时打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9244387/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com