java-创建时打开Android滑动抽屉
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-创建时打开Android滑动抽屉,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2456字,纯文字阅读大概需要4分钟。
内容图文
![java-创建时打开Android滑动抽屉](/upload/InfoBanner/zyjiaocheng/691/fd2d54b431464349a5c9b6607e34aebc.jpg)
我想要一个在应用启动时打开的滑块.它将通过按钮等打开,当用户关闭它时,将有更多按钮可供访问.滑动抽屉可以吗?我会在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);
}
}
内容总结
以上是互联网集市为您收集整理的java-创建时打开Android滑动抽屉全部内容,希望文章能够帮你解决java-创建时打开Android滑动抽屉所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。