想了解Android仿微信朋友圈全文、收起功能的实例代码的相关内容吗,wildma在本文为您仔细讲解android 全文 收起的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:android,全文,收起,android,微信朋友圈收起,下面大家一起来学习吧。
前言
一般在社交APP中都有类似朋友圈的功能,其中发表的动态内容很长的时候不可能让它全部显示。这里就需要做一个仿微信朋友圈全文、收起功能来解决该问题。在网上看到一个例子-->https://m.qb5200.com/,写的很不错,但是有个bug,他这个Demo只有在条目固定的时候才正常,当增加、删除条目的时候会出现全文、收起显示混乱的问题。原因是他使用了固定的position作为key来保存当前显示的状态。这篇文章在他的基础上进行优化。
效果图
具体代码
(详细解释在代码注释中都有,这里就省略了)
MainActivity.java
packagehttps://m.qb5200.com/com.wildma.wildmaexpandfoldtext;
importhttps://m.qb5200.com/android.os.Bundle;
importhttps://m.qb5200.com/android.support.v7.app.AppCompatActivity;
importhttps://m.qb5200.com/android.support.v7.widget.LinearLayoutManager;
importhttps://m.qb5200.com/android.support.v7.widget.RecyclerView;
importhttps://m.qb5200.com/java.util.ArrayList;
importhttps://m.qb5200.com/java.util.List;
/**
https://m.qb5200.com/*https://m.qb5200.com/Authorhttps://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/wildma
https://m.qb5200.com/*https://m.qb5200.com/DATEhttps://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/2017/8/3
https://m.qb5200.com/*https://m.qb5200.com/Deshttps://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/${TODO}
https://m.qb5200.com/*/
publichttps://m.qb5200.com/classhttps://m.qb5200.com/MainActivityhttps://m.qb5200.com/extendshttps://m.qb5200.com/AppCompatActivityhttps://m.qb5200.com/{
https://m.qb5200.com/https://m.qb5200.com/privatehttps://m.qb5200.com/RecyclerViewhttps://m.qb5200.com/mRecyclerView;
https://m.qb5200.com/https://m.qb5200.com/List<ExpandFoldTextBean>https://m.qb5200.com/mListhttps://m.qb5200.com/=https://m.qb5200.com/newhttps://m.qb5200.com/ArrayList<>();
https://m.qb5200.com/https://m.qb5200.com/@Override
https://m.qb5200.com/https://m.qb5200.com/protectedhttps://m.qb5200.com/voidhttps://m.qb5200.com/onCreate(Bundlehttps://m.qb5200.com/savedInstanceState)https://m.qb5200.com/{
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/super.onCreate(savedInstanceState);
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/setContentView(R.layout.activity_main);
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/initData();
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/ExpandFoldTextAdapterhttps://m.qb5200.com/adapterhttps://m.qb5200.com/=https://m.qb5200.com/newhttps://m.qb5200.com/ExpandFoldTextAdapter(mList,https://m.qb5200.com/this);
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/mRecyclerViewhttps://m.qb5200.com/=https://m.qb5200.com/(RecyclerView)https://m.qb5200.com/findViewById(R.id.recyclerview);
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/mRecyclerView.setLayoutManager(newhttps://m.qb5200.com/LinearLayoutManager(this,https://m.qb5200.com/LinearLayoutManager.VERTICAL,https://m.qb5200.com/false));
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/mRecyclerView.setAdapter(adapter);
https://m.qb5200.com/https://m.qb5200.com/}
https://m.qb5200.com/https://m.qb5200.com//**
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/*https://m.qb5200.com/初始化数据
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/*/
https://m.qb5200.com/https://m.qb5200.com/privatehttps://m.qb5200.com/voidhttps://m.qb5200.com/initData()https://m.qb5200.com/{
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/Stringhttps://m.qb5200.com/longContenthttps://m.qb5200.com/=https://m.qb5200.com/"-->游泳、快走、慢跑、骑自行车,及一切有氧运动都能锻炼心脏。有氧运动好处多:能锻炼心肺、增强循环系统功能、燃烧脂肪、加大肺活量、降低血压,甚至能预防糖尿病,减少心脏病的发生。美国运动医学院建议,想知道有氧运动强度是否合适,可在运动后测试心率,以达到最高心率的60%—90%为宜。如果想通过有氧运动来减肥,可以选择低度到中度的运动强度,同时延长运动时间,这种方法消耗的热量更多。运动频率每周3—5次,每次20—60分钟。想要锻炼肌肉,可以练举重、做体操以及其他重复伸、屈肌肉的运动。肌肉锻炼可以燃烧热量、增强骨密度、减少受伤,尤其是关节受伤的几率,还能预防骨质疏松。https://m.qb5200.com/在做举重运动前,先测一下,如果连续举8次你最多能举多重的东西,就从这个重量开始练习。当你可以连续12次举起这个重量时,试试增加5%的重量。注意每次练习时,要连续举8—12次,这样可以达到肌肉最大耐力的70%—80%,锻炼效果较好。每周2—3次,但要避免连续两天锻炼同一组肌肉群,https://m.qb5200.com/以便让肌肉有充分的恢复时间。";
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/Stringhttps://m.qb5200.com/shortContenthttps://m.qb5200.com/=https://m.qb5200.com/"-->健身是一种体育项目,如各种徒手健美操、韵律操、形体操以及各种自抗力动作。";
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/forhttps://m.qb5200.com/(inthttps://m.qb5200.com/ihttps://m.qb5200.com/=https://m.qb5200.com/0;https://m.qb5200.com/ihttps://m.qb5200.com/<https://m.qb5200.com/20;https://m.qb5200.com/i++)https://m.qb5200.com/{
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/ExpandFoldTextBeanhttps://m.qb5200.com/beanhttps://m.qb5200.com/=https://m.qb5200.com/newhttps://m.qb5200.com/ExpandFoldTextBean();
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/ifhttps://m.qb5200.com/(ihttps://m.qb5200.com/%https://m.qb5200.com/2https://m.qb5200.com/==https://m.qb5200.com/0)https://m.qb5200.com/{
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/bean.setContent(ihttps://m.qb5200.com/+https://m.qb5200.com/shortContent);
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/bean.setId(i);
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/}https://m.qb5200.com/elsehttps://m.qb5200.com/{
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/bean.setContent(ihttps://m.qb5200.com/+https://m.qb5200.com/longContent);
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/bean.setId(i);
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/}
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/mList.add(bean);
https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/https://m.qb5200.com/}
https://m.qb5200.com/https://m.qb5200.com/}
}