1. 程式人生 > >Diycode開源項目 ImageActivity分析

Diycode開源項目 ImageActivity分析

target ref pos ted margin font sed 開源項目 turn

1.首先看一下效果

1.1做成了一個GIF

  技術分享

1.2.我用格式工廠有點問題,大小無法調到手機這樣的大小,目前還沒有解決方案。

1.3.網上有免費的MP4->GIF,參考一下這個網站吧。

1.4.講解一下這個圖片吧,首先是從話題中點擊了其中一張圖片,進入圖片Activity,然後可以自由放大,自由翻轉。


2.分析一下繼承的BaseImageActivity

2.1因為ImageActivity繼承了BaseImageActivtiy,首先看看源代碼。

技術分享
/*
 * Copyright 2017 GcsSloop
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    
http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Last modified 2017-03-15 20:02:59 * * GitHub:
https://github.com/GcsSloop * Website: http://www.gcssloop.com * Weibo: http://weibo.com/GcsSloop */ package com.gcssloop.diycode.base.app; import android.content.Intent; import java.util.ArrayList; /** * 對數據進行預處理 */ public abstract class BaseImageActivity extends BaseActivity { public
static final String ALL_IMAGE_URLS = "all_images"; public static final String CURRENT_IMAGE_URL = "current_image"; protected static final String MODE_NORMAL = "normal"; protected static final String MODE_ERROR = "error"; protected String mCurrentMode = MODE_NORMAL; protected ArrayList<String> images = new ArrayList<>(); // 所有圖片 protected String current_image_url = null; // 當前圖片 protected int current_image_position = 0; // 當前圖片位置 @Override protected void initDatas() { super.initDatas(); // 初始化圖片 url 和 圖片集合,保證兩個數據都存在 Intent intent = getIntent(); // 沒有傳遞當前圖片,設置模式為錯誤 String imageUrl = intent.getStringExtra(CURRENT_IMAGE_URL); if (imageUrl == null || imageUrl.isEmpty()) { toastShort("沒有傳遞圖片鏈接"); mCurrentMode = MODE_ERROR; return; } mCurrentMode = MODE_NORMAL; ArrayList<String> temp = intent.getStringArrayListExtra(ALL_IMAGE_URLS); if (temp == null || temp.size() <= 0) { // 記錄當前圖片,計算位置 images.clear(); images.add(imageUrl); } else if (temp.size() > 0) { // 如果圖片集合大於0 images = new ArrayList<>(temp); } if (!images.contains(imageUrl)) { images.add(imageUrl); } current_image_url = imageUrl; current_image_position = images.indexOf(current_image_url); } }
View Code

2.2


3.一些示例文字

第三段


4.一些示例文字

第四段


5.一些示例文字

第五段


6.一些示例文字

第六段



Diycode開源項目 ImageActivity分析