Android App----Mr Expense 之主界面

2024-05-13 08:48

本文主要是介绍Android App----Mr Expense 之主界面,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这篇文章放在草稿箱很多天了,知道现在才发出来,主要是我的主界面和Listview相关甚大,但是博主对listview用法始终掌握不好,这几天有空的时候就看了好多文章,总结一下listview,感觉很强大的酱紫。

-------------------------------------------


先上个被我抛弃的主界面:


main.xml:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><ListView android:id="@id/android:list"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:divider="@null"android:cacheColorHint="@android:color/transparent" />     
</LinearLayout>

listview.xml:

<?xml version="1.0" encoding="utf-8"?>  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent" android:layout_height="match_parent" >  <ImageView android:id="@+id/image"  android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_centerVertical="true" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:adjustViewBounds="true"  android:padding="2dp" />  <TextView android:id="@+id/title"  android:layout_width="wrap_content" android:layout_height="wrap_content"  android:layout_toRightOf="@id/image"  android:layout_alignParentTop="true"  android:layout_alignWithParentIfMissing="true"   android:textSize="30dp" /><TextViewandroid:id="@+id/text"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_below="@id/title"android:layout_toRightOf="@id/image"android:ellipsize="marquee"android:gravity="bottom"android:singleLine="true"android:textSize="19dp" /></RelativeLayout> 

public class Main extends ListActivity {  private String[] mListTitle = { "food", "transport", "utilities", "healthcare","clothes","entertainment","others"};  private String[] mListStr = {  "今天你吃饭了吗", "今天你坐公交车了没", "今天你修爱疯了木", "今天你打针了么", "今天你买球鞋了嘛","今天你K歌了麽","也许还有一些东西-。=" };  private Object[] mListImage={R.drawable.shiwu,R.drawable.jiaotong,R.drawable.shebei,R.drawable.yiliao,R.drawable.yifu,R.drawable.yule,R.drawable.zawu};ListView mListView = null;  ArrayList<Map<String,Object>> mData= new ArrayList<Map<String,Object>>();  @Override  protected void onCreate(Bundle savedInstanceState) {  requestWindowFeature(Window.FEATURE_NO_TITLE);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);setContentView(R.layout.main);mListView = getListView();  int lengh = mListTitle.length;  for(int i =0; i < lengh; i++) {  Map<String,Object> item = new HashMap<String,Object>(); item.put("image", mListImage[i]);  item.put("title", mListTitle[i]);  item.put("text", mListStr[i]);mData.add(item);   }  SimpleAdapter adapter = new SimpleAdapter(this,mData,R.layout.listitem,  new String[]{"image","title","text","background"},new int[]{R.id.image,R.id.title,R.id.text});  setListAdapter(adapter);  mListView.setOnItemClickListener(new OnItemClickListener() {  @Override  public void onItemClick(AdapterView<?> adapterView,View view, int position,  long id) {  Toast.makeText(Main.this,"您选择了标题:" + mListTitle[position] + "内容:"+mListStr[position], Toast.LENGTH_LONG).show();  }  });  super.onCreate(savedInstanceState);  }  
} 

说明:

0、主界面很简单,就一个Listview,然后每个item有3个view,好白有木有!

1、android:divider="@null"这句话会把item之间的黑线去掉,哎没去掉之前更是不忍直视

2、一开始我的Listview充满不了屏幕,然后上网问啊,有个人跟我说layout设置vertical,然后权重设1,于是如代码所示,

android:layout_weight="1",但其实是没用的,我之所以没去掉,主要是看到能让我想起它的其他作用,权重可以分配位置的大小,但是也不是那么想当然的分配,有篇文章深入探讨了:ht@tp://mobile.51cto.com/abased-375428.htm

3、android:cacheColorHint="@android:color/transparent" 去底色,在这里可用可不用

4、Listview用的RelativeLayout,发现比LinearLayout复杂太多,常用属性:ht@tp://blog.csdn.net/notenlife/article/details/7256363

5、android:layout_centerVertical="true"让图片在imageview中居中

6、为了让Listview充满屏幕,只能调节字体的大小了,不知道还有没有其他简单高效的方法

7、android:gravity="bottom" text在最下面体现

8、android:ellipsize="marquee"  android:singleLine="true"单行 跑马,当然在这里是多余的。另外,想要跑马灯,设置focus,详见:ht@tp://www.cnblogs.com/Gaojiecai/archive/2013/06/18/3142783.html

9、下面来说说Listview

Listview和数据关联要用到adapter,常见的ArrayAdapter,SimpleAdapter,还有继承BaseAdapter

这个主界面是用的SimpleAdapter(this,data,layout,string,int)

getListView()是只有继承ListActivity才有的


但是这个主界面越看越不爽,有木有,虽然简约是我的风格,but做人做事那是两码子事,果断throw IT away。

我接下来就想给每个item都上个色,五彩斑斓的多好,然后其他地方也微调下。差不多就酱紫。

于是我在main.xml加了android:layout_background="@+id/background",然后在Activity中直接把颜色put进item中,然后设置下adapter,想当然以为Listview能五颜六色了,发现报错了。。。看来这个只是用于整个Listview的背景色。

然后呢,我就用了Listview的BaseAdapter,自定义总可以了吧。

public class Main extends ListActivity {private String[] mListTitle = { "food", "transport", "utilities", "healthcare","clothes","entertainment","others"};  private String[] mListStr = {  "今天你吃饭了吗", "今天你坐公交车了没", "今天你修爱疯了木", "今天你打针了么", "今天你买球鞋了嘛","今天你K歌了麽","也许还有一些东西 -。=" };  private int[] mListImage={R.drawable.shiwu,R.drawable.jiaotong,R.drawable.shebei,R.drawable.yiliao,R.drawable.yifu,R.drawable.yule,R.drawable.zawu};private int[] mListColor=new int []{0xffff0033,0xff66cccc,0xff3333cc,0xff66cc33,0xffffcc33,0xffff9900,0xffcc6600};ListView mListView = null;MyListAdapter myAdapter = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {requestWindowFeature(Window.FEATURE_NO_TITLE);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);setContentView(R.layout.main);mListView = getListView(); myAdapter = new MyListAdapter(this);setListAdapter(myAdapter);mListView.setOnItemClickListener(new OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> adapterView, View view, int position,long id) {View v=adapterView.getChildAt(position);Toast.makeText(Main.this,"您选择了" + mListTitle[position], Toast.LENGTH_LONG).show();}});super.onCreate(savedInstanceState);}class MyListAdapter extends BaseAdapter {private Context mContext;public MyListAdapter(Context context) { mContext = context;}public int getCount() {   return mListStr.length;}@Overridepublic boolean areAllItemsEnabled() {return false;}public Object getItem(int position) {return position;}public long getItemId(int position) {return position;}public View getView(int position, View convertView, ViewGroup parent) {ImageView image = null;TextView title = null;TextView text = null;if (convertView == null) {convertView = LayoutInflater.from(mContext).inflate(R.layout.listitem, null);image = (ImageView) convertView.findViewById(R.id.image);title =(TextView) convertView.findViewById(R.id.title);text= (TextView) convertView.findViewById(R.id.text);}  int colorPos = position % mListColor.length;convertView.setBackgroundColor(mListColor[colorPos]);image.setImageResource(mListImage[position]);title.setText(mListTitle[position]);text.setText(mListStr[position]);return convertView;}}}

效果图:


既然走的是“色”的路线,那么欢迎界面也该搞得“色”一点,这样跳跃才不会太大,O(∩_∩)O~

OK,到此主界面先这样,还木有数据的处理呢。

作业可以先handle了,接下来该去看看怎么搞数据了。


-------------------------

4.23 nju

这篇关于Android App----Mr Expense 之主界面的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/985232

相关文章

Android实现在线预览office文档的示例详解

《Android实现在线预览office文档的示例详解》在移动端展示在线Office文档(如Word、Excel、PPT)是一项常见需求,这篇文章为大家重点介绍了两种方案的实现方法,希望对大家有一定的... 目录一、项目概述二、相关技术知识三、实现思路3.1 方案一:WebView + Office Onl

Android实现两台手机屏幕共享和远程控制功能

《Android实现两台手机屏幕共享和远程控制功能》在远程协助、在线教学、技术支持等多种场景下,实时获得另一部移动设备的屏幕画面,并对其进行操作,具有极高的应用价值,本项目旨在实现两台Android手... 目录一、项目概述二、相关知识2.1 MediaProjection API2.2 Socket 网络

Android实现悬浮按钮功能

《Android实现悬浮按钮功能》在很多场景中,我们希望在应用或系统任意界面上都能看到一个小的“悬浮按钮”(FloatingButton),用来快速启动工具、展示未读信息或快捷操作,所以本文给大家介绍... 目录一、项目概述二、相关技术知识三、实现思路四、整合代码4.1 Java 代码(MainActivi

Android Mainline基础简介

《AndroidMainline基础简介》AndroidMainline是通过模块化更新Android核心组件的框架,可能提高安全性,本文给大家介绍AndroidMainline基础简介,感兴趣的朋... 目录关键要点什么是 android Mainline?Android Mainline 的工作原理关键

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n

如何解决idea的Module:‘:app‘platform‘android-32‘not found.问题

《如何解决idea的Module:‘:app‘platform‘android-32‘notfound.问题》:本文主要介绍如何解决idea的Module:‘:app‘platform‘andr... 目录idea的Module:‘:app‘pwww.chinasem.cnlatform‘android-32

Android实现打开本地pdf文件的两种方式

《Android实现打开本地pdf文件的两种方式》在现代应用中,PDF格式因其跨平台、稳定性好、展示内容一致等特点,在Android平台上,如何高效地打开本地PDF文件,不仅关系到用户体验,也直接影响... 目录一、项目概述二、相关知识2.1 PDF文件基本概述2.2 android 文件访问与存储权限2.

Android Studio 配置国内镜像源的实现步骤

《AndroidStudio配置国内镜像源的实现步骤》本文主要介绍了AndroidStudio配置国内镜像源的实现步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、修改 hosts,解决 SDK 下载失败的问题二、修改 gradle 地址,解决 gradle

在Android平台上实现消息推送功能

《在Android平台上实现消息推送功能》随着移动互联网应用的飞速发展,消息推送已成为移动应用中不可或缺的功能,在Android平台上,实现消息推送涉及到服务端的消息发送、客户端的消息接收、通知渠道(... 目录一、项目概述二、相关知识介绍2.1 消息推送的基本原理2.2 Firebase Cloud Me

Android中Dialog的使用详解

《Android中Dialog的使用详解》Dialog(对话框)是Android中常用的UI组件,用于临时显示重要信息或获取用户输入,本文给大家介绍Android中Dialog的使用,感兴趣的朋友一起... 目录android中Dialog的使用详解1. 基本Dialog类型1.1 AlertDialog(