1.界面需求图

Android 模拟新浪微博-随便看看栏目_第1张图片

2.实现过程

  01.新建一个新的布局(xml) view.xml

 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     android:layout_width="fill_parent" 4     android:layout_height="fill_parent" 5     android:orientation="horizontal" > 6  7     <!-- 左边图片 --> 8     <ImageView 9         android:id="@+id/img"10         android:padding="10dp"11         android:layout_width="48dp"12         android:layout_height="48dp" />13     <!-- 右边布局 -->14     <LinearLayout15         android:layout_width="fill_parent"16         android:layout_height="wrap_content"17         android:orientation="vertical" >18 19         <!-- 上边布局 -->20         <LinearLayout21             android:layout_width="fill_parent"22             android:layout_height="wrap_content"23             android:orientation="horizontal" >24 25             <!-- 发布人 -->26             <TextView27                 android:id="@+id/name"28                 android:layout_width="wrap_content"29                 android:layout_height="wrap_content" />30             <!-- 发布时间 -->31             <TextView32                 android:id="@+id/publish"33                 android:layout_width="fill_parent"34                 android:layout_height="wrap_content"35                 android:gravity="right" />36         </LinearLayout>37         <!-- 下边发布内容 -->38        <TextView39             android:id="@+id/info"40             android:layout_width="wrap_content"41             android:layout_height="wrap_content" />42     </LinearLayout>43 44 </LinearLayout>
View.xml

  02.activity_main.xml 中 拖一个ListView

    宽度 高度 属性设置为 "fill_parent"

  03.MainActivity.java 中的主要代码

 1 //1. 2     private ListView lv; 3      4     @Override 5     protected void onCreate(Bundle savedInstanceState) { 6         super.onCreate(savedInstanceState); 7         setContentView(R.layout.activity_main); 8          9         //2. Simple10         SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.view, new String[] { "img", "name", "info", "publish" },11                 new int[] { R.id.img, R.id.name, R.id.info, R.id.publish });12         13         //3.找到 绑定 listView14         lv = (ListView) findViewById(R.id.lv);15         16         //4.填充到lv17         lv.setAdapter(adapter);18     }19 20     //3.要填充数据21     private List<Map<String, Object>> getData() {22         List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();23         Map<String, Object> map = new HashMap<String, Object>();24         map.put("name", "Dota2专区");25         map.put("info", "你的历史或许也将成为他的故事《玩家·故事》支持一波~");26         map.put("publish", "1分钟前");27         map.put("img", R.drawable.p1);28         list.add(map);29         map = new HashMap<String, Object>();30         map.put("name", "IT程序员");31         map.put("info", "成功,不是追求别人眼中的最好,而是把自己能做的事情做得最好。");32         map.put("publish", "5分钟前");33         map.put("img", R.drawable.p2);34         list.add(map);35         map = new HashMap<String, Object>();36         map.put("name", "电脑报");37         map.put("info", "【总理叹:还是苹果三星用户多!】昨日,李克强总理在参观中关村创业大街的时候,众多员工也纷纷拿出手机拍照、合影。李克强见状询问众人:你们都用的什么手机?“苹果”、“三星”....众人争相回答。听完回答之后,李克强感慨了一句:还是苹果跟三星的多啊...");38         map.put("publish", "7分钟前");39         map.put("img", R.drawable.p3);40         list.add(map);41         map = new HashMap<String, Object>();42         map.put("name", "人民网");43         map.put("info", "【安徽萧县县政府办公室被盗 警方尚未公布损失】3月27日8时许,萧县公安局110指挥中心接县政府办公室报案称,县政府办公室窗户被撬,室内翻动凌乱,同时被撬的还有另外两办公室。 5月6日,嫌犯张某、朱某被抓获,目前被刑事拘留。被盗具体损失,警方尚未公布。(安徽商报)");44         map.put("publish", "8分钟前");45         map.put("img", R.drawable.p4);46         list.add(map);47         map = new HashMap<String, Object>();48         map.put("name", "互联网那点事");49         map.put("info", "真搞不懂58同城为什么要收购中华英才网这样一家垃圾邮件公司!");50         map.put("publish", "10分钟前");51         map.put("img", R.drawable.p5);52         map = new HashMap<String, Object>();53         map.put("name", "极客头条");54         map.put("info", "由 GitHub 推出的开源编辑器 Atom 项目已经一年,从下面的信息图表可以看到一年来该项目的成果。目前,Atom 1.0版本正在酝酿之中,会尽快发布(By @ImportNew 推荐)。极客头条:");55         map.put("publish", "20分钟前");56         map.put("img", R.drawable.p6);57         list.add(map);58         59         return list;60     } 
View Code

3.界面运行后 图

Android 模拟新浪微博-随便看看栏目_第2张图片

4.Demo

https://github.com/cnfanhua/A-CopyWeibo

    

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android内存优化
  2. Android群英传笔记——第一章:Android体系
  3. Android工程目录结构 Android四大组件 Co
  4. Android(安卓)日历开发教程[一]
  5. android每日一问1【2011-8-30】
  6. Android(安卓)Service生命周期及用法
  7. View的使用方法
  8. Android实战经验之图像处理及特效处理的
  9. android的Activity窗口模式
  10. Android(安卓)API Guides---Creating an