当前位置: 移动技术网 > IT编程>移动开发>Android > Android仿新浪微博个人信息界面及其他效果

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

我要坐车网,曹阜忠,上网导航网站

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

根据用户id获取用户信息接口:

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

补充

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>

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网