listview组件的应用—模拟微博


ListView组件的应用(模拟新浪微博界面)

阶段一:进行主界面的布局                           

Main.xml具体代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

在layout下新建item.xml,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/image"
        android:padding="10dp"
        android:layout_width="48dp"
        android:layout_height="48dp" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/name"
                android:paddingTop="10dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/publish"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:paddingTop="10dp"
                android:gravity="right" />
        </LinearLayout>

        <TextView
            android:id="@+id/content"
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

</LinearLa
<p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Tahoma; font-size: 14px; line-height: 24px;">阶段二:编写MainActivity并进行相应的事件处理,具体代码如下:</p><pre class="java" name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-size: 14px; line-height: 24px;">package com.lks.sinablog;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class MainActivity extends Activity {
	private List<Map<String, ?>> data;
	private ListView listItem;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		listItem = (ListView) this.findViewById(R.id.list);
		data = getData();
		SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.item,
				new String[] { "image", "name", "publish", "content" },
				new int[] { R.id.image, R.id.name, R.id.publish, R.id.content });
		listItem.setAdapter(adapter);
		listItem.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapter, View view, int position,
					long id) {
				Map<String, Object> item=(Map<String, Object>) data.get(position);
				Toast.makeText(getApplicationContext(), item.get("name")+"\n\n"+item.get("content"), Toast.LENGTH_LONG).show();
				
			}
		});
	}

	private List<Map<String, ?>> getData() {
		List<Map<String, ?>> data = new ArrayList<Map<String, ?>>();
		Map<String, Object> item = new HashMap<String, Object>();
		item.put("image", R.drawable.image1);
		item.put("name", "世界末日");
		item.put("publish", "1分钟前");
		item.put("content", "我过得还可以,不好不坏,不惊不喜,一切只是还可以。这样的生活我觉得也挺好。");
		data.add(item);
		item = new HashMap<String, Object>();
		item.put("image", R.drawable.image2);
		item.put("name", "吹乱了章节");
		item.put("publish", "9分钟前");
		item.put("content",
				"我们都在等,等到最后或许是彼此转身都没有回首,此刻我们背对背,下一刻你是否会转身,我只能等待,或许你也在等待,那我们只能在等待中消散,最后谁都没有回头,就像车站离别,拥抱完就各自上车,又或许你忘了我叫什么……");
		data.add(item);
		item = new HashMap<String, Object>();
		item.put("image", R.drawable.image3);
		item.put("name", "回不去的过去");
		item.put("publish", "23分钟前");
		item.put("content", "开始听一些很旧的歌,才明白原来生活中的一切都会老去。");
		data.add(item);
		item = new HashMap<String, Object>();
		item.put("image", R.drawable.image4);
		item.put("name", "夜,未央");
		item.put("publish", "43分钟前");
		item.put("content", "我不贪心,只希望现在的朋友都不变,以后还是可以相聚,无关金钱名利,大碗喝酒大口吃肉,能潇洒开心的日子就忘记痛苦。老了,以后相拥回忆往事,在黄昏下相望。");
		data.add(item);
		item = new HashMap<String, Object>();
		item.put("image", R.drawable.image5);
		item.put("name", "浅光旧人不覆");
		item.put("publish", "1小时前");
		item.put("content",
				"似乎所有的开始都有一个写好了的结局就算你自己再怎么努力也扭转不了注定,此刻我羡慕的是曾经我所不珍惜的……");
		data.add(item);
		return data;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

阶段三:自定义标题栏

首先,修改标题栏的高度和背景,在res\values下新建title.xml文件,在其中添加代码:

<resources>
    <style name="TitleBackground"> 
    <item name="android:background">#FF0000</item> 
</style>

<style name="selfdefine" parent="android:Theme"> 
    <item name="android:windowTitleSize">30dp</item> 
    <item name="android:windowTitleBackgroundStyle">@style/TitleBackground</item> 
</style>
</resources>

然后修改AndroidManifest.xml文件:

<activity
            android:name=".MainActivity"
            android:theme="@style/selfdefine"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

 

运行结果显示:

                              

 
 
<p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px; background-color: rgb(250, 247, 239);"><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px; font-family: 楷体; font-size: 18px;">  分析问题:</span></span></p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px; background-color: rgb(250, 247, 239);"> </p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px; background-color: rgb(250, 247, 239);"><span style="margin: 0px; padding: 0px; font-family: 楷体;"><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px; font-size: 18px;">1.ListView及ListView_Item的使用</span></span></span></p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px; background-color: rgb(250, 247, 239);"> </p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px; background-color: rgb(250, 247, 239);"><span style="margin: 0px; padding: 0px; font-family: 楷体;"><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px; font-size: 18px;">2.实体类</span></span></span></p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px; background-color: rgb(250, 247, 239);"> </p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px; background-color: rgb(250, 247, 239);"><span style="margin: 0px; padding: 0px; font-family: 楷体;"><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px; font-size: 18px;">3.ListView自定义适配器的书写</span></span></span></p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px; background-color: rgb(250, 247, 239);"> </p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px; background-color: rgb(250, 247, 239);"><span style="margin: 0px; padding: 0px; font-family: 楷体;"><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px; font-size: 18px;">4.ListView的绑定数据源与控件</span></span></span></p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px; background-color: rgb(250, 247, 239);"> </p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px; background-color: rgb(250, 247, 239);"><span style="margin: 0px; padding: 0px; font-family: 楷体;"><span style="margin: 0px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; font-size: 18px;">5.</span><span style="margin: 0px; padding: 0px; font-size: 18px;">继承:BaseAdapter</span></span></span></p>

【资源说明】 1.项目代码功能经验证ok,确保稳定可靠运行。欢迎下载使用!在使用过程中,如有问题或建议,请及时私信沟通。 2.主要针对各个计算机相关专业,包括计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网等领域的在校学生、专业教师或企业员工使用。 3.项目具有丰富的拓展空间,不仅可作为入门进阶,也可直接作为毕设、课程设计、大作业、初期项目立项演示等用途。 4.当然也鼓励大家基于此进行二次开发。 5.期待你能在项目中找到乐趣和灵感,也欢迎你的分享和反馈! 本文介绍了基于QEM(Quadric Error Metrics,二次误差度量)的优化网格简化算法的C和C++实现源码及其相关文档。这一算法主要应用于计算机图形学领域,用于优化三维模型的多边形数量,使之在保持原有模型特征的前提下实现简化。简化的目的是为了提高渲染速度,减少计算资源消耗,以及便于网络传输等。 本项目的核心是网格简化算法的实现,而QEM作为该算法的核心,是一种衡量简化误差的数学方法。通过计算每个顶点的二次误差矩阵来评估简化操作的误差,并以此来指导网格简化过程。QEM算法因其高效性和准确性在计算机图形学中广泛应用,尤其在实时渲染和三维打印领域。 项目代码包含C和C++两种语言版本,这意味着它可以在多种开发环境中运行,增加了其适用范围。对于计算机相关专业的学生、教师和行业从业者来说,这个项目提供了丰富的学习和实践机会。无论是作为学习编程的入门材料,还是作为深入研究计算机图形学的项目,该项目都具有实用价值。 此外,项目包含的论文文档为理解网格简化算法提供了理论基础。论文详细介绍了QEM算法的原理、实施步骤以及与其他算法的对比分析。这不仅有助于加深对算法的理解,也为那些希望将算法应用于自己研究领域的人员提供了参考资料。 资源说明文档强调了项目的稳定性和可靠性,并鼓励用户在使用过程中提出问题或建议,以便不断地优化和完善项目。文档还提醒用户注意查看,以获取使用该项目的所有必要信息。 项目的文件名称列表中包含了加水印的论文文档、资源说明文件和实际的项目代码目录,后者位于名为Mesh-Simplification-master的目录下。用户可以将这些资源用于多种教学和研究目的,包括课程设计、毕业设计、项目立项演示等。 这个项目是一个宝贵的资源,它不仅提供了一个成熟的技术实现,而且为进一步的研究和学习提供了坚实的基础。它鼓励用户探索和扩展,以期在计算机图形学领域中取得更深入的研究成果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值