日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android抽屉效果

發布時間:2023/12/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android抽屉效果 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

SlidingDrawer類雖然已經不推薦使用了,但有時如果效果簡單的話用用也無妨,反正我有有點懷念,主要是它使用簡單,只能上下或者左右滑動,而且剛開始的時候,方向不能指定,

布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
??? android:layout_width="match_parent"
??? android:layout_height="match_parent" ?
??? android:orientation="vertical"
??? android:background="#000099">
?? ?
??? <SlidingDrawer
??????? android:id="@+id/slidingdrawer"
??????? android:layout_width="match_parent"
??????? android:layout_height="wrap_content"
??????? android:content="@+id/content"
??????? android:handle="@+id/handle"
??????? android:orientation="vertical" >
??????? <ImageView
??????????? android:id="@id/handle"
??????????? android:layout_width="wrap_content"
??????????? android:layout_height="wrap_content"
??????????? android:src="@drawable/lo19" >
??????? </ImageView>
??????? <LinearLayout
??????????? android:id="@id/content"
??????????? android:layout_width="match_parent"
??????????? android:layout_height="match_parent"
??????????? android:background="#008800">
??????????? <TextView
??????????????? android:layout_width="match_parent"
??????????????? android:layout_height="match_parent"
??????????????? android:text="隱藏的內容"/>
??????? </LinearLayout>
??? </SlidingDrawer>
??? <TextView
??????? android:layout_width="match_parent"
??????? android:layout_height="wrap_content"
??????? android:text="bottom textView"
??????? android:textAppearance="?android:attr/textAppearanceLarge"
??????? android:gravity="center_vertical|center_horizontal"/>
</LinearLayout>

在主界面中不寫什么代碼就可以滑了,

如果要寫一些方法,主要是下面幾個方法

SlidingDrawer sd = (SlidingDrawer)findViewById(R.id.slidingdrawer);?
?????????
??????? sd.setOnDrawerOpenListener(new OnDrawerOpenListener(){?
??????????? public void onDrawerOpened() {?
??????????????? // TODO Auto-generated method stub?
??????????? }?
??????? });?
??????? sd.setOnDrawerCloseListener(new OnDrawerCloseListener(){?
??????????? public void onDrawerClosed() {?
??????????????? // TODO Auto-generated method stub?
??????????? }?
??????? });?
??????? sd.setOnDrawerScrollListener(new OnDrawerScrollListener(){?
??????????? public void onScrollEnded() {?
??????????????? // TODO Auto-generated method stub?
??????????? }?
??????????? public void onScrollStarted() {?
??????????????? // TODO Auto-generated method stub?
??????????? }????
??????? });

下面這抽屜把手機上的應用程序的圖標在抽屜中以縮小的圖標來顯示,這是轉自網絡的, 我覺得可能以后有用就收藏到此了,如有侵僅,還請告知

布局文件

<?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/lo13" ?
??????????????? 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/lo19" /> ?
??????? </SlidingDrawer> ?
???? ?
??? </RelativeLayout> ?

操作上面配置的文件的Activity類

package com.example.t;

import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.view.Menu;
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 MainActivity 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.main_2); ?
??????? 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.lo19);// 響應開抽屜事件 ?
??????????????????????????????????????????????????????????????? // ,把圖片設為向下的 ?
??????????? } ?
??????? }); ?
??????? sd.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() { ?
??????????? @Override ?
??????????? public void onDrawerClosed() { ?
??????????????? iv.setImageResource(R.drawable.lo13);// 響應關抽屜事件 ?
??????????? } ?
??????? }); ?
??? } ?
?
??? 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() {
?? ??? ?super();
?? ?}

?? ??? ?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(MainActivity.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;
??????? }
?}

??? }


總結

以上是生活随笔為你收集整理的android抽屉效果的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。