Android抽屉菜单SlidingDrawer 简单使用
发布时间:2020-12-14 23:26:39 所属栏目:Java 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 ?xml version="1.0" encoding="utf-8"? !-- 需要设置SlidingDrawer的handle和content的id -- SlidingDrawer xmlns:android="http://schemas.android.c
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考
<?xml version="1.0" encoding="utf-8"?>
<!-- 需要设置SlidingDrawer的handle和content的id --> <SlidingDrawer xmlns:android="http://schemas.android.com/apk/res/android" ? ? android:id="@+id/slidingdrawer" ? ? android:layout_width="match_parent" ? ? android:layout_height="match_parent" ? ? android:content="@+id/content" ? ? android:handle="@+id/handle" ? ? android:orientation="horizontal" > ? ? <!-- 设置handle,来处理滑动抽屉 --> ? ? <ImageButton ? ? ? ? android:id="@id/handle" ? ? ? ? android:layout_width="50dp" ? ? ? ? android:layout_height="50dp" ? ? ? ? android:src="@drawable/ic_launcher" /> ? ? <!-- 设置内容View --> ? ? <RelativeLayout ? ? ? ? android:id="@id/content" ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="match_parent" ? ? ? ? android:background="#F0F0F0" > ? ? ? ? <TextView ? ? ? ? ? ? android:id="@+id/show_tv" ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:gravity="center_vertical|center_horizontal" ? ? ? ? ? ? android:text="简单抽屉效果" ? ? ? ? ? ? android:textColor="#333333" ? ? ? ? ? ? android:textSize="18sp" /> ? ? ? ? <ListView ? ? ? ? ? ? android:id="@+id/lv" ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_below="@id/show_tv" > ? ? ? ? </ListView> ? ? </RelativeLayout> public class DrawerAdpater extends BaseAdapter { List<String> list; LayoutInflater inflater; public MyAdpater(Context context,List<String> list) { this.list = list; this.inflater = LayoutInflater.from(context); } public int getCount() { return list.size(); } public long getItemId(int position) { return position; } public View getView(int position,View convertView,ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.item,null); } TextView textView = (TextView) convertView.findViewById(R.id.text); textView.setText(list.get(position)); return convertView; } @Override public Object getItem(int position) { return list.get(position); } } 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |