栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Android滑动抽屉在创建时打开

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android滑动抽屉在创建时打开

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 SlidingDrawerslide;    private TextView     tv_commentDisplay;@Overridepublic 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");}@Overridepublic void onScrollEnded() {}@Overridepublic void onScrollStarted() {    if (slide.isOpened())        handleImage.setImageResource(R.drawable.ic_tray_collapse);    else {        handleImage.setImageResource(R.drawable.ic_tray_expand);    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/431308.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号