Android編程實現(xiàn)抽屜效果的方法示例
本文實例講述了Android編程實現(xiàn)抽屜效果的方法。分享給大家供大家參考,具體如下:
今天在手機(jī)上實現(xiàn)了抽屜效果,其實很簡單,但是效果卻很酷。
首先在layout 下設(shè)置xml布局文件
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <SlidingDrawer android:id="@+id/sliding" android:layout_width="match_parent" android:layout_height="match_parent" android:content="@+id/allApps" android:handle="@+id/imageViewIcon" android:orientation="vertical" > <GridView android:id="@+id/allApps" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/bk" android:columnWidth="60dp" android:gravity="center" android:horizontalSpacing="10dp" android:numColumns="auto_fit" android:padding="10dp" android:stretchMode="columnWidth" android:verticalSpacing="10dp" /> <ImageView android:id="@+id/imageViewIcon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/touch_handler" /> </SlidingDrawer> </RelativeLayout>
SlidingDrawer就是重要的抽屜控件 ,handle是抽屜的拖動按鈕,content是抽屜中的內(nèi)容。
然后建立 chouti的activity類:
import android.app.Activity; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView; import android.widget.SlidingDrawer; public class Chouti extends Activity { private GridView gv; private SlidingDrawer sd; private ImageView iv; private List<ResolveInfo> apps; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.slidingdrawer); loadApps(); gv = (GridView) findViewById(R.id.allApps); sd = (SlidingDrawer) findViewById(R.id.sliding); iv = (ImageView) findViewById(R.id.imageViewIcon); gv.setAdapter(new GridAdapter()); sd.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener()// 開抽屜 { @Override public void onDrawerOpened() { iv.setImageResource(R.drawable.touch_handler);// 響應(yīng)開抽屜事件 // ,把圖片設(shè)為向下的 } }); sd.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() { @Override public void onDrawerClosed() { iv.setImageResource(R.drawable.touch_handler);// 響應(yīng)關(guān)抽屜事件 } }); } private void loadApps() { Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); apps = getPackageManager().queryIntentActivities(intent, 0); } public class GridAdapter extends BaseAdapter { public GridAdapter() { } public int getCount() { // TODO Auto-generated method stub return apps.size(); } public Object getItem(int position) { // TODO Auto-generated method stub return apps.get(position); } public long getItemId(int position) { // TODO Auto-generated method stub return position; } public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub ImageView imageView = null; if (convertView == null) { imageView = new ImageView(Chouti.this); imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); imageView.setLayoutParams(new GridView.LayoutParams(50, 50)); } else { imageView = (ImageView) convertView; } ResolveInfo ri = apps.get(position); imageView.setImageDrawable(ri.activityInfo .loadIcon(getPackageManager())); return imageView; } } }
loadApps方法是得到主界面上的圖片和文字。
然后設(shè)置的自定義adapter中去。
看下運行后效果:
向上滑動imageview按鈕后:
為了體現(xiàn)更好的效果,可以用兩張滑動圖片,一張朝上的,一張朝下的。根據(jù)監(jiān)聽器做相應(yīng)的切換。
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》及《Android資源操作技巧匯總》
希望本文所述對大家Android程序設(shè)計有所幫助。
- Android開發(fā)之DrawerLayout實現(xiàn)抽屜效果
- Android編程實現(xiàn)抽屜效果的方法詳解
- Android 自定義View實現(xiàn)抽屜效果
- Android自定義控件仿QQ抽屜效果
- Android DrawerLayout實現(xiàn)抽屜效果實例代碼
- Android 抽屜效果的導(dǎo)航菜單實現(xiàn)代碼實例
- Android實現(xiàn)自定義滑動式抽屜菜單效果
- Android App中DrawerLayout抽屜效果的菜單編寫實例
- Android SlidingDrawer 抽屜效果的實現(xiàn)
- Android的Activity跳轉(zhuǎn)動畫各種效果整理
- Android Tween動畫之RotateAnimation實現(xiàn)圖片不停旋轉(zhuǎn)效果實例介紹
- Android實現(xiàn)圖片輪播效果的兩種方法
相關(guān)文章
android支付寶客戶端html5網(wǎng)頁無法自動關(guān)閉問題的解決方法
這篇文章主要為大家詳細(xì)介紹了android支付寶客戶端html5網(wǎng)頁無法自動關(guān)閉問題的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04Android中通知Notification使用實例(振動、燈光、聲音)
這篇文章主要介紹了Android中通知Notification使用實例,實現(xiàn)振動,燈光,聲音等效果,感興趣的小伙伴們可以參考一下2016-01-01Android開發(fā)中如何去掉app標(biāo)題欄的實現(xiàn)
這篇文章主要介紹了Android開發(fā)中如何去掉app標(biāo)題欄的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04Flutter進(jìn)階之實現(xiàn)動畫效果(四)
這篇文章主要為大家詳細(xì)介紹了Flutter進(jìn)階之實現(xiàn)動畫效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-08-08Android中Toolbar隨著ScrollView滑動透明度漸變效果實現(xiàn)
這篇文章主要介紹了Android中Toolbar隨著ScrollView滑動透明度漸變效果實現(xiàn),非常不錯,具有參考借鑒價值,需要的的朋友參考下2017-01-01Android自定義密碼樣式 黑點轉(zhuǎn)換成特殊字符
這篇文章主要為大家詳細(xì)介紹了Android自定義密碼樣式的制作方法,黑點換成¥、%等特殊字符,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07Flutter 使用cached_image_network優(yōu)化圖片加載體驗
在 Flutter 中,cached_image_network 即提供了緩存網(wǎng)絡(luò)圖片功能,同時還提供了豐富的加載過程指示。本文就來看下cached_image_network的具體使用2021-05-05