第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

android怎么實現(xiàn)類似滑動式抽屜的效果

標簽:
Android

  今天在手机上实现了抽屉效果,其实很简单,但是效果却很酷。

           首先在layout 下设置xml布局文件 

       


  1. <?xml version="1.0" encoding="utf-8"?>  

  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  

  3.     android:layout_width="fill_parent"  

  4.     android:layout_height="fill_parent" >  

  5.   

  6.     <SlidingDrawer  

  7.         android:id="@+id/sliding"  

  8.         android:layout_width="match_parent"  

  9.         android:layout_height="match_parent"  

  10.         android:content="@+id/allApps"  

  11.         android:handle="@+id/imageViewIcon"  

  12.         android:orientation="vertical" >  

  13.   

  14.         <GridView  

  15.             android:id="@+id/allApps"  

  16.             android:layout_width="wrap_content"  

  17.             android:layout_height="wrap_content"  

  18.             android:background="@drawable/bk"  

  19.             android:columnWidth="60dp"  

  20.             android:gravity="center"  

  21.             android:horizontalSpacing="10dp"  

  22.             android:numColumns="auto_fit"  

  23.             android:padding="10dp"  

  24.             android:stretchMode="columnWidth"  

  25.             android:verticalSpacing="10dp" />  

  26.   

  27.         <ImageView  

  28.             android:id="@+id/imageViewIcon"  

  29.             android:layout_width="wrap_content"  

  30.             android:layout_height="wrap_content"  

  31.             android:src="@drawable/touch_handler" />  

  32.     </SlidingDrawer>  

  33.   

  34. </RelativeLayout>  


        SlidingDrawer就是重要的抽屉控件 ,handle是抽屉的拖动按钮,content是抽屉中的内容。


      然后建立 chouti的activity类:


[html] view plain copy

  1. import android.app.Activity;  

  2. import android.content.Intent;  

  3. import android.content.pm.ResolveInfo;  

  4. import android.os.Bundle;  

  5. import android.view.View;  

  6. import android.view.ViewGroup;  

  7. import android.widget.BaseAdapter;  

  8. import android.widget.GridView;  

  9. import android.widget.ImageView;  

  10. import android.widget.SlidingDrawer;  

  11.   

  12. public class Chouti extends Activity {  

  13.     private GridView gv;  

  14.     private SlidingDrawer sd;  

  15.     private ImageView iv;  

  16.     private List<ResolveInfo> apps;  

  17.   

  18.     /** Called when the activity is first created. */  

  19.     @Override  

  20.     public void onCreate(Bundle savedInstanceState) {  

  21.         super.onCreate(savedInstanceState);  

  22.         setContentView(R.layout.slidingdrawer);  

  23.         loadApps();  

  24.         gv = (GridView) findViewById(R.id.allApps);  

  25.         sd = (SlidingDrawer) findViewById(R.id.sliding);  

  26.         iv = (ImageView) findViewById(R.id.imageViewIcon);  

  27.         gv.setAdapter(new GridAdapter());  

  28.         sd.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener()// 开抽屉  

  29.         {  

  30.             @Override  

  31.             public void onDrawerOpened() {  

  32.                 iv.setImageResource(R.drawable.touch_handler);// 响应开抽屉事件  

  33.                                                                 // ,把图片设为向下的  

  34.             }  

  35.         });  

  36.         sd.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {  

  37.             @Override  

  38.             public void onDrawerClosed() {  

  39.                 iv.setImageResource(R.drawable.touch_handler);// 响应关抽屉事件  

  40.             }  

  41.         });  

  42.     }  

  43.   

  44.     private void loadApps() {  

  45.         Intent intent = new Intent(Intent.ACTION_MAIN, null);  

  46.         intent.addCategory(Intent.CATEGORY_LAUNCHER);  

  47.   

  48.         apps = getPackageManager().queryIntentActivities(intent, 0);  

  49.     }  

  50.   

  51.     public class GridAdapter extends BaseAdapter {  

  52.         public GridAdapter() {  

  53.   

  54.         }  

  55.   

  56.         public int getCount() {  

  57.             // TODO Auto-generated method stub  

  58.             return apps.size();  

  59.         }  

  60.   

  61.         public Object getItem(int position) {  

  62.             // TODO Auto-generated method stub  

  63.             return apps.get(position);  

  64.         }  

  65.   

  66.         public long getItemId(int position) {  

  67.             // TODO Auto-generated method stub  

  68.             return position;  

  69.         }  

  70.   

  71.         public View getView(int position, View convertView, ViewGroup parent) {  

  72.             // TODO Auto-generated method stub  

  73.             ImageView imageView = null;  

  74.             if (convertView == null) {  

  75.                 imageView = new ImageView(Chouti.this);  

  76.                 imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);  

  77.                 imageView.setLayoutParams(new GridView.LayoutParams(50, 50));  

  78.             } else {  

  79.                 imageView = (ImageView) convertView;  

  80.             }  

  81.   

  82.             ResolveInfo ri = apps.get(position);  

  83.             imageView.setImageDrawable(ri.activityInfo  

  84.                     .loadIcon(getPackageManager()));  

  85.   

  86.             return imageView;  

  87.         }  

  88.   

  89.     }  

  90. }  


loadApps方法是得到主界面上的图片和文字。


   然后设置的自定义adapter中去。

 

    

    为了体现更好的效果,可以用两张滑动图片,一张朝上的,一张朝下的。根据监听器做相应的切换。

原文链接:http://www.apkbus.com/blog-914653-68369.html

點擊查看更多內(nèi)容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消