Android編程實(shí)現(xiàn)抽屜效果的方法示例
本文實(shí)例講述了Android編程實(shí)現(xiàn)抽屜效果的方法。分享給大家供大家參考,具體如下:
今天在手機(jī)上實(shí)現(xiàn)了抽屜效果,其實(shí)很簡(jiǎ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是抽屜的拖動(dòng)按鈕,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中去。
看下運(yùn)行后效果:
向上滑動(dòng)imageview按鈕后:
為了體現(xiàn)更好的效果,可以用兩張滑動(dòng)圖片,一張朝上的,一張朝下的。根據(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ù)庫(kù)操作技巧總結(jié)》及《Android資源操作技巧匯總》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android開發(fā)之DrawerLayout實(shí)現(xiàn)抽屜效果
- Android編程實(shí)現(xiàn)抽屜效果的方法詳解
- Android 自定義View實(shí)現(xiàn)抽屜效果
- Android自定義控件仿QQ抽屜效果
- Android DrawerLayout實(shí)現(xiàn)抽屜效果實(shí)例代碼
- Android 抽屜效果的導(dǎo)航菜單實(shí)現(xiàn)代碼實(shí)例
- Android實(shí)現(xiàn)自定義滑動(dòng)式抽屜菜單效果
- Android App中DrawerLayout抽屜效果的菜單編寫實(shí)例
- Android SlidingDrawer 抽屜效果的實(shí)現(xiàn)
- Android的Activity跳轉(zhuǎn)動(dòng)畫各種效果整理
- Android Tween動(dòng)畫之RotateAnimation實(shí)現(xiàn)圖片不停旋轉(zhuǎn)效果實(shí)例介紹
- Android實(shí)現(xiàn)圖片輪播效果的兩種方法
相關(guān)文章
android支付寶客戶端html5網(wǎng)頁(yè)無(wú)法自動(dòng)關(guān)閉問題的解決方法
這篇文章主要為大家詳細(xì)介紹了android支付寶客戶端html5網(wǎng)頁(yè)無(wú)法自動(dòng)關(guān)閉問題的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04Android中通知Notification使用實(shí)例(振動(dòng)、燈光、聲音)
這篇文章主要介紹了Android中通知Notification使用實(shí)例,實(shí)現(xiàn)振動(dòng),燈光,聲音等效果,感興趣的小伙伴們可以參考一下2016-01-01Android開發(fā)中如何去掉app標(biāo)題欄的實(shí)現(xiàn)
這篇文章主要介紹了Android開發(fā)中如何去掉app標(biāo)題欄的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04簡(jiǎn)單實(shí)現(xiàn)Android端搜索框示例詳解
這篇文章主要為大家介紹了簡(jiǎn)單實(shí)現(xiàn)Android端搜索框示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11Flutter進(jìn)階之實(shí)現(xiàn)動(dòng)畫效果(四)
這篇文章主要為大家詳細(xì)介紹了Flutter進(jìn)階之實(shí)現(xiàn)動(dòng)畫效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08Android中Toolbar隨著ScrollView滑動(dòng)透明度漸變效果實(shí)現(xiàn)
這篇文章主要介紹了Android中Toolbar隨著ScrollView滑動(dòng)透明度漸變效果實(shí)現(xiàn),非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下2017-01-01Android自定義密碼樣式 黑點(diǎn)轉(zhuǎn)換成特殊字符
這篇文章主要為大家詳細(xì)介紹了Android自定義密碼樣式的制作方法,黑點(diǎn)換成¥、%等特殊字符,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07Flutter 使用cached_image_network優(yōu)化圖片加載體驗(yàn)
在 Flutter 中,cached_image_network 即提供了緩存網(wǎng)絡(luò)圖片功能,同時(shí)還提供了豐富的加載過程指示。本文就來(lái)看下cached_image_network的具體使用2021-05-05