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

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

Android仿新浪微博個人信息界面及其他效果

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

本教程為大家分享了Android微博個人信息界面設(shè)計代碼,供大家參考,具體內(nèi)容如下

根據(jù)用戶ID獲取用戶信息接口:
http://open.weibo.com/wiki/2/users/show

如果你已經(jīng)實現(xiàn)前面的功能那個這個人信息界面便是小菜一碟,此處不作敘述。

補充

1.時間處理類:

處理微博發(fā)出時間距現(xiàn)在時刻的時間。應(yīng)該是比較容易理解的。

/** * 時間處理類 */public class DateUtils {  public String getInterval(String createtime) { //傳入的時間格式必須類似于2012-8-21 17:53:20這樣的格式    String interval = null;    SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");    ParsePosition pos = new ParsePosition(0);    Date d1 = sd.parse(createtime, pos);    //用現(xiàn)在距離1970年的時間間隔new Date().getTime()減去以前的時間距離1970年的時間間隔d1.getTime()得出的就是以前的時間與現(xiàn)在時間的時間間隔    long time = new Date().getTime() - d1.getTime();// 得出的時間間隔是毫秒    int day = 24 * 3600000;    int week = day * 7;    if (time / 1000 < 10 && time / 1000 >= 0) {      //如果時間間隔小于10秒則顯示“剛剛”time/10得出的時間間隔的單位是秒      interval = "剛剛";    } else if (time / 3600000 < 24 && time / 3600000 > 0) {      //如果時間間隔小于24小時則顯示多少小時前      int h = (int) (time / 3600000);//得出的時間間隔的單位是小時      interval = h + "小時前";    } else if (time / 60000 < 60 && time / 60000 > 0) {      //如果時間間隔小于60分鐘則顯示多少分鐘前      int m = (int) ((time % 3600000) / 60000);//得出的時間間隔的單位是分鐘      interval = m + "分鐘前";    } else if (time / 1000 < 60 && time / 1000 > 0) {      //如果時間間隔小于60秒則顯示多少秒前      int se = (int) ((time % 60000) / 1000);      interval = se + "秒前";    } else if (time / day < 7 && time / day > 0) {      int d = (int) (time / day);      interval = d + "天前";    } else if (time / week < 5 && time / week > 0) {      int w = (int) (time / week);      interval = w + "周前";    } else {      //大于一個月的,則顯示正常的時間,但是不顯示秒      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");      ParsePosition pos2 = new ParsePosition(0);      Date d2 = (Date) sdf.parse(createtime, pos2);      interval = sdf.format(d2);    }    return interval;  }}

2.字符串中表情處理類:

正則表達式匹配相應(yīng)表情字段,若匹配則使用SpannableString將該字段的文字用表情圖片代替。

public class StringUtils {  public static SpannableString getEmotionContent(final Context context, final TextView tv, String source) {    SpannableString spannableString = new SpannableString(source);    Resources res = context.getResources();    String regexEmotion = "http://[([/u4e00-/u9fa5//w])+//]";    Pattern patternEmotion = Pattern.compile(regexEmotion);    Matcher matcherEmotion = patternEmotion.matcher(spannableString);    Bitmap scaleBitmap;    int size = (int) tv.getTextSize();    while (matcherEmotion.find()) {      // 獲取匹配到的具體字符      String key = matcherEmotion.group();      // 匹配字符串的開始位置      int start = matcherEmotion.start();      // 利用表情名字獲取到對應(yīng)的圖片      Integer imgRes = EmotionUtils.getImgByName(key);      if (imgRes != null && size > 0) {        // 壓縮表情圖片        Bitmap bitmap = BitmapFactory.decodeResource(res, imgRes);        if (bitmap != null) {          scaleBitmap = Bitmap.createScaledBitmap(bitmap, size, size, true);          ImageSpan span = new ImageSpan(context, scaleBitmap);          spannableString.setSpan(span, start, start + key.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);        }      }    }    return spannableString;  }}

3.manifest文件:

由于該應(yīng)用涉及諸多權(quán)限,故需要聲明權(quán)限。此處由于上次多張圖片會使內(nèi)存溢出,故需申請額外內(nèi)存

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="study.sinatest"> <!-- 訪問網(wǎng)絡(luò)的權(quán)限 -->  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>  <uses-permission android:name="android.permission.INTERNET"/>  <!-- 在SDCard中創(chuàng)建與刪除文件權(quán)限 -->  <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>  <!-- 往SDCard寫入數(shù)據(jù)權(quán)限 -->  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>  <application  <!-- 此處由于上次多張圖片會使內(nèi)存溢出,故需申請額外內(nèi)存 -->    android:largeHeap="true"    android:allowBackup="true"    android:hardwareAccelerated="false"    android:icon="@mipmap/weibologo"    android:label="@string/app_name"    android:supportsRtl="true"    android:theme="@style/AppTheme">    <activity      android:name=".SplashActivity"      android:configChanges="keyboardHidden"      android:launchMode="singleTask"      android:screenOrientation="portrait">      <intent-filter>        <action android:name="android.intent.action.MAIN"/>        <category android:name="android.intent.category.LAUNCHER"/>      </intent-filter>    </activity>    <activity android:name=".LoginActivity"/>    <activity android:name=".MainActivity"/>    <activity android:name=".HomeActivity"/>    <activity android:name=".WriteActivity"/>    <activity android:name=".CommentActivity"/>    <activity android:name=".MeActivity"/>    <activity android:name=".MoreActivity"/>    <!-- 授權(quán)頁面 -->    <activity      android:name=".OAuthActivity"      android:launchMode="singleTask">      <intent-filter>        <action android:name="android.intent.action.VIEW"/>        <category android:name="android.intent.category.DEFAULT"/>        <category android:name="android.intent.category.BROWSABLE"/>        <data android:scheme="philn"/>      </intent-filter>    </activity>    <!-- 谷歌服務(wù)權(quán)限 -->    <meta-data      android:name="com.google.android.gms.version"      android:value="@integer/google_play_services_version"/>  </application>  <supports-screens    android:anyDensity="true"    android:largeScreens="true"    android:normalScreens="true"/></manifest>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 远安县| 罗田县| 长宁县| 黄大仙区| 韶山市| 嵊泗县| 张家界市| 集安市| 龙川县| 隆昌县| 临清市| 湘阴县| 凭祥市| 镇平县| 浦北县| 台南市| 上犹县| 五峰| 延津县| 天津市| 长葛市| 内江市| 剑川县| 迁安市| 调兵山市| 桐梓县| 伊通| 昌宁县| 剑川县| 韶关市| 东港市| 论坛| 清苑县| 元阳县| 会昌县| 麻栗坡县| 定边县| 八宿县| 綦江县| 定边县| 宁阳县|