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

 更新时间:2016年11月21日 14:30:56   作者:DeMon辉  
这篇文章主要为大家详细介绍了Android仿新浪微博个人信息界面及其他效果设计,如正则表达式如何匹配相应表情字段,处理微博发出时间距现在时刻的时间,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本教程为大家分享了Android微博个人信息界面设计代码,供大家参考,具体内容如下

根据用户ID获取用户信息接口:
http://open.weibo.com/wiki/2/users/show

如果你已经实现前面的功能那个这个人信息界面便是小菜一碟,此处不作叙述。

补充

1.时间处理类:

处理微博发出时间距现在时刻的时间。应该是比较容易理解的。

/**
 * 时间处理类
 */
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);

    //用现在距离1970年的时间间隔new Date().getTime()减去以前的时间距离1970年的时间间隔d1.getTime()得出的就是以前的时间与现在时间的时间间隔
    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.字符串中表情处理类:

正则表达式匹配相应表情字段,若匹配则使用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 = "\\[([\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();
      // 利用表情名字获取到对应的图片
      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文件:

由于该应用涉及诸多权限,故需要声明权限。此处由于上次多张图片会使内存溢出,故需申请额外内存

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="study.sinatest">
 <!-- 访问网络的权限 -->
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  <uses-permission android:name="android.permission.INTERNET"/>
  <!-- 在SDCard中创建与删除文件权限 -->
  <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
  <!-- 往SDCard写入数据权限 -->
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <application
  <!-- 此处由于上次多张图片会使内存溢出,故需申请额外内存 -->
    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"/>
    <!-- 授权页面 -->
    <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>
    <!-- 谷歌服务权限 -->
    <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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • 最近较流行的效果 Android自定义View实现倾斜列表/图片

    最近较流行的效果 Android自定义View实现倾斜列表/图片

    最近较流行的效果,这篇文章主要介绍了Android自定义View实现倾斜列表/图片的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-06-06
  • 浅谈Android客户端与服务器的数据交互总结

    浅谈Android客户端与服务器的数据交互总结

    这篇文章主要介绍了浅谈Android客户端与服务器的数据交互总结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-09-09
  • Android中FontMetrics的几个属性全面讲解

    Android中FontMetrics的几个属性全面讲解

    下面小编就为大家带来一篇Android中FontMetrics的几个属性全面讲解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-11-11
  • Android编程实现自定义分享列表ACTION_SEND功能的方法

    Android编程实现自定义分享列表ACTION_SEND功能的方法

    这篇文章主要介绍了Android编程实现自定义分享列表ACTION_SEND功能的方法,结合实例形式详细分析了自定义分享列表功能的步骤与具体操作技巧,需要的朋友可以参考下
    2017-02-02
  • Flutter使用SingleTickerProviderStateMixin报错解决

    Flutter使用SingleTickerProviderStateMixin报错解决

    这篇文章主要为大家介绍了Flutter使用SingleTickerProviderStateMixin报错解决示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-08-08
  • Android实现ListView控件的多选和全选功能实例

    Android实现ListView控件的多选和全选功能实例

    这篇文章主要介绍了Android实现ListView控件的多选和全选功能,结合实例形式分析了ListView控件多选及全选功能的布局与功能实现技巧,需要的朋友可以参考下
    2017-07-07
  • Kotlin中协变、逆变和不变示例详解

    Kotlin中协变、逆变和不变示例详解

    这篇文章主要给大家介绍了关于Kotlin中协变、逆变和不变的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
    2018-04-04
  • Android仿微信右滑返回功能的实例代码

    Android仿微信右滑返回功能的实例代码

    这篇文章主要介绍了Android仿微信右滑返回功能的实例代码,需要的朋友可以参考下
    2017-09-09
  • Android 简单封装获取验证码倒计时功能

    Android 简单封装获取验证码倒计时功能

    倒计时效果相信大家都不陌生,我们可以使用很多种方法去实现此效果,这里自己采用 CountDownTimer 定时器简单封装下此效果,方便我们随时调用。下面小编给大家分享android验证码倒计时封装方法,感兴趣的朋友一起看看吧
    2018-01-01
  • Android Matrix源码详解

    Android Matrix源码详解

    本篇文章主要介绍了Android Matrix,在android中Matrix是进行过图像处理的,有兴趣的可以了解一下。
    2016-12-12

最新评论