国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

Android編程仿Iphone拖動(dòng)相片特效Gallery的簡(jiǎn)單應(yīng)用示例

2019-12-12 04:55:46
字體:
供稿:網(wǎng)友

本文實(shí)例講述了Android編程仿Iphone拖動(dòng)相片特效Gallery的簡(jiǎn)單應(yīng)用。分享給大家供大家參考,具體如下:

Step 1:準(zhǔn)備圖片素材.

將icon2,icon3,icon4,icon5,icon6五張圖片導(dǎo)入res/drawable里加上icon.png本身一共有6張圖片.

Step 2:新建Android工程,命名為GalleryDemo.

Step 3:設(shè)計(jì)UI,修改main.xml代碼如下:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/white" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/myTextView01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:gravity="center_vertical|center_horizontal" /> <Gallery android:id="@+id/myGallery1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="bottom" /></LinearLayout>

Step 4:設(shè)計(jì)主程序類GalleryDemo.Java代碼如下:

package com.android.test;import com.android.test.R.drawable;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.Gallery;import android.widget.ImageView;public class GalleryDemo extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ((Gallery) findViewById(R.id.myGallery1)).setAdapter(new ImageAdapter(  this)); } public class ImageAdapter extends BaseAdapter { /* 類成員 myContext為Context父類 */ private Context myContext; /* 使用res/drawable圖片作為圖片來源 */ private int[] myImageIds = { drawable.icon, drawable.icon2,  drawable.icon3, drawable.icon4, drawable.icon5, drawable.icon6}; /* 構(gòu)造器只有一個(gè)參數(shù),即要存儲(chǔ)的Context */ public ImageAdapter(Context c) {  this.myContext = c; } /* 返回所有已定義的圖片總數(shù)量 */ public int getCount() {  return this.myImageIds.length; } /* 利用getItem方法,取得目前容器中圖像的數(shù)組ID */ public Object getItem(int position) {  return position; } public long getItemId(int position) {  return position; } /* 取得目前欲顯示的圖像View,傳入數(shù)組ID值使之讀取與成像 */ public View getView(int position, View convertView, ViewGroup parent) {  /* 創(chuàng)建一個(gè)ImageView對(duì)象 */  ImageView i = new ImageView(this.myContext);  i.setImageResource(this.myImageIds[position]);  i.setScaleType(ImageView.ScaleType.FIT_XY);  /* 設(shè)置這個(gè)ImageView對(duì)象的寬高,單位為dip */  i.setLayoutParams(new Gallery.LayoutParams(120, 120));  return i; } /* 依據(jù)距離中央的位移量 利用getScale返回views的大小(0.0f to 1.0f) */ public float getScale(boolean focused, int offset) {  /* Formula: 1 / (2 ^ offset) */  return Math.max(0, 1.0f / (float) Math.pow(2, Math.abs(offset))); } }}

Step 5:run it,效果如下圖:

 

注明:該代碼基本參照Android SDK開發(fā)范例代碼大全

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android圖形與圖像處理技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 海晏县| 韶关市| 甘洛县| 文登市| 临清市| 道孚县| 信宜市| 宝丰县| 手游| 石城县| 射洪县| 库车县| 迁安市| 施秉县| 八宿县| 新邵县| 英吉沙县| 涿鹿县| 乌鲁木齐市| 凯里市| 大余县| 洛川县| 登封市| 土默特右旗| 宁都县| 菏泽市| 武宁县| 永昌县| 朔州市| 阿尔山市| 仲巴县| 武冈市| 镇安县| 齐河县| 南开区| 神农架林区| 建湖县| 沅江市| 连平县| 瑞金市| 荣成市|