android 自定义listview实现仿微信/QQ设置界面的开发
2015-06-21 11:28
976 查看
现在类似QQ微信的设置界面非常流行,实现起来也是非常简单的,现在我们自己动手写一个。
先来看一下效果图:
由于没有找到合适的图标,所以用xml写了个绿色的方块暂时替代了。
接下来我们看看项目的整体结构
可以看到项目确实非常简单,configitem.xml是listview中间那一段的item,configitemedit是listview最后的带edittext的item,head.xml是listview账户头像部分的item。
接下来是MainActivity的代码:
先来看一下效果图:
由于没有找到合适的图标,所以用xml写了个绿色的方块暂时替代了。
接下来我们看看项目的整体结构
可以看到项目确实非常简单,configitem.xml是listview中间那一段的item,configitemedit是listview最后的带edittext的item,head.xml是listview账户头像部分的item。
接下来是MainActivity的代码:
package com.example.piyel_000.myapplication; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import java.util.ArrayList; import java.util.List; public class MainActivity extends ActionBarActivity { public static final String[] s = {"年龄","性别", "学院","所在社团","简介"}; public static final String[] s2 = {"20","男", "物理与电子工程学院","启承教学社"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView listView = (ListView) findViewById(R.id.listView4); BaseAdapter baseAdapter=new BaseAdapter() { @Override public int getCount() { return 10; } @Override public Object getItem(int i) { return null; } @Override public long getItemId(int i) { return 0; } @Override public View getView(int i, View view, ViewGroup viewGroup) { LayoutInflater inflater = getLayoutInflater(); View configview=null; switch (i) { case 9: configview = inflater.inflate(R.layout.divider, null, false); configview.setMinimumHeight(50); break; case 8: configview = inflater.inflate(R.layout.configitemedit, null, false); TextView itemthint = (TextView) configview.findViewById(R.id.configitemname); EditText itemedit = (EditText) configview.findViewById(R.id.itemedit); itemthint.setText(s[4]); itemedit.setHint("请输入简介..."); break; case 7: configview = inflater.inflate(R.layout.divider, null, false); configview.setMinimumHeight(80); break; case 2: configview = inflater.inflate(R.layout.divider, null, false); configview.setMinimumHeight(90); break; case 1: configview = inflater.inflate(R.layout.head, null, false); TextView headid = (TextView) configview.findViewById(R.id.idtext); TextView headname = (TextView) configview.findViewById(R.id.nametext); ImageView headimg = (ImageView) configview.findViewById(R.id.faceimage); break; case 0: configview = inflater.inflate(R.layout.divider, null, false); configview.setMinimumHeight(90); break; default: configview = (View) inflater.inflate(R.layout.configitem, null, false); TextView itemname = (TextView) configview.findViewById(R.id.configitemname); ImageView itemimg = (ImageView) configview.findViewById(R.id.configitemimg); TextView context = (TextView) configview.findViewById(R.id.itemcontext); itemname.setText(s[i-3]); context.setText(s2[i-3]); } return configview; } }; listView.setAdapter(baseAdapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }具体的项目源码请到这里下载:http://download.csdn.net/download/piyell/8826033
相关文章推荐
- 社交巨头三国杀:微信、WhatsApp、Line到底有啥区别?
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件