這篇文章將為大家詳細講解有關(guān)Android應(yīng)用中怎么實現(xiàn)一個抽屜效果,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供開陽網(wǎng)站建設(shè)、開陽做網(wǎng)站、開陽網(wǎng)站設(shè)計、開陽網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、開陽企業(yè)網(wǎng)站模板建站服務(wù),十多年開陽做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
首先在layout 下設(shè)置xml布局文件
<?xml version="1.0" encoding="utf-8"?>
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 Listapps; /** 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; } } }
關(guān)于Android應(yīng)用中怎么實現(xiàn)一個抽屜效果就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。