
本次项目主要包含了QQ消息、联系人和动态三个选项卡界面的切换,其中消息界面设计的很详细,有消息列表和消息内容,在点击消息对话框后,会跳转到聊天界面,还会把联系人姓名传值过来。联系人和动态的界面就是很简单的两张截图,点击底下的TextVIEw实现切换。
二、开发环境 三、详细设计 1、主界面的搭建在最外层选择的是linearLayout布局,里面放置一个FrameLayout,用于显示主体内容。
最底下放置了一个子布局,里面是三个TextVIEw,分别为消息、联系人和动态,三个ID分别命名为menu1、menu2、menu3,占比都是1,字体大小相同,都是居中显示。预览图如下:
布局文件的代码如下:
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical" tools:context=".MainActivity"> <FrameLayout androID:ID="@+ID/content" androID:layout_wIDth="match_parent" androID:layout_height="0dp" androID:layout_weight="9"></FrameLayout> <linearLayout androID:ID="@+ID/menu" androID:layout_wIDth="match_parent" androID:layout_height="0dp" androID:layout_weight="0.5"> <TextVIEw androID:ID="@+ID/menu1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:gravity="center" androID:text="消息" androID:textSize="25sp" androID:layout_weight="1"/> <TextVIEw androID:ID="@+ID/menu2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:gravity="center" androID:text="联系人" androID:textSize="25sp" androID:layout_weight="1"/> <TextVIEw androID:ID="@+ID/menu3" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:gravity="center" androID:text="动态" androID:textSize="25sp" androID:layout_weight="1"/> </linearLayout></linearLayout> 2、消息界面的搭建 在消息界面的设置中,最上面是一个子linearLayout(线性布局),左侧放置头像ImageVIEw,右侧是TextVIEw,用于显示用户昵称。
接着放置了一个TextVIEw,字体颜色为白色,背景颜色为绿色,用于显示 “ 消息 ” 标题。
底下是ListVIEw,用于显示好友列表。预览图如下:
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" tools:context=".frag1" androID:orIEntation="vertical"> <linearLayout androID:ID="@+ID/img" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:background="#00BCD4"> <ImageVIEw androID:ID="@+ID/head" androID:layout_wIDth="80dp" androID:layout_height="80dp" androID:background="@drawable/head"/> <TextVIEw androID:ID="@+ID/num" androID:layout_wIDth="match_parent" androID:layout_height="50dp" androID:textSize="25sp" androID:gravity="bottom"/> </linearLayout> <TextVIEw androID:layout_wIDth="match_parent" androID:layout_height="45dp" androID:background="#8BC34A" androID:gravity="center" androID:text="消息" androID:textcolor="#FFFFFF" androID:textSize="28sp" /> <ListVIEw androID:ID="@+ID/lv" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:padding="5dp"/></linearLayout> 3、联系人界面的搭建 联系人界面展示的是QQ联系人的截图,放在drawable文件夹中引用。
<?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"> <ImageVIEw androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:background="@drawable/lxr"></ImageVIEw></linearLayout> 4、动态界面的搭建 同联系人界面,展示的是QQ的动态截图。
本次项目的核心界面,在消息界面中选中一个好友,点进去,就会跳转到此聊天界面。
最上面的TextVIEw就是用来显示传递过来的昵称,字体颜色为黑色,背景颜色为绿色。
下面的ImageVIEw就放置了一张聊天截图,一切从简嘛。
<?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"> <TextVIEw androID:ID="@+ID/It_name" androID:layout_wIDth="match_parent" androID:layout_height="80dp" androID:textcolor="#000000" androID:textSize="60dp" androID:textAlignment="center" androID:background="#8BC34A" androID:gravity="center_horizontal"> </TextVIEw> <ImageVIEw androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:background="@drawable/lt"> </ImageVIEw></linearLayout> 6、跳转功能实现 6.1、选项卡的切换 在MainActivity调用了一个onClick方法,点击选项卡,跳转到不同的activity。
public voID onClick(VIEw v) { ft=fm.beginTransaction(); switch(v.getID()){ case R.ID.menu1: ft.replace(R.ID.content,new frag1()); break; case R.ID.menu2: ft.replace(R.ID.content,new frag2()); break; case R.ID.menu3: ft.replace(R.ID.content,new frag3()); break; default: break; } ft.commit(); } 6.2、消息列表的适配器 主要实现了好友的头像用定义好的icons数组显示,昵称用name数组显示,消息内容用message数组显示。
class MyBaseAdapter extends BaseAdapter{ @OverrIDe public int getCount(){ //返回ListVIEw Item条目代表的对象 return name.length; } //得到item的ID @OverrIDe public Object getItem(int i){ return name[i]; } @OverrIDe public long getItemID(int i){ return i; } @OverrIDe public VIEw getVIEw(int i, VIEw convertVIEw, VIEwGroup vIEwGroup){ //获取item中的VIEw视图 VIEw vIEw=VIEw.inflate(frag1.this.getContext(),R.layout.frIEnd_item, null); //初始化vIEw对象的控件 TextVIEw tv_name=vIEw.findVIEwByID(R.ID.item_name); TextVIEw tv_message=vIEw.findVIEwByID(R.ID.item_message); ImageVIEw iv=vIEw.findVIEwByID(R.ID.iv); tv_name.setText(name[i]); tv_message.setText(message[i]); iv.setimageResource(icons[i]); return vIEw; } } 7、传值的实现 在check.java中,先用setContentVIEw方法设置好布局文件,接着将声明好的TextVIEw也就是tv_name和activity_check中的It_name进行绑定,完了之后就是声明意图intent,取出key对应的value值,获取name,然后再用setText方法显示出来。
public class check extends AppCompatActivity { private TextVIEw tv_name; @OverrIDe protected voID onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_check); tv_name=findVIEwByID(R.ID.It_name); Intent intent=getIntent(); //取出key对应的value值 String name=intent.getStringExtra("name"); tv_name.setText(name); }} 四、项目效果 1、主界面默认显示为消息界面,显示消息列表。
2、选择好友腾讯并点击,进入聊天界面,好友的昵称也被传递过来。
3、点击联系人选项卡,跳转到联系人界面。
4、点击动态选项卡,跳转到动态界面。
本次QQ应用项目主要考验学生对于ListVIEw和intent的使用,对多个页面之间的跳转和传值要熟稔于心,这些知识点在今后的AndroID项目中会经常使用,因此希望大家能够熟练掌握上述知识点的使用,可以在此基础上延伸各种项目。
六、项目下载项目的drawable文件夹里面的图片都是博主自己截取的,大家下载下来源码后按照自己的需求用自己的截图替换掉就可以了,在博主的公众号里面回复:QQ应用,即可获取源码,还有很多AndroID项目等你来学习,还等什么,加入我们吧。
总结你人生的每一步都必须靠自己的能力完成,自己肚子没有料,手上没本事,认识再多的人也没用。人脉只能给你机会,但抓住机会还是要靠真本事。所以啊,提升自己,比到处逢迎别人更重要。
以上是内存溢出为你收集整理的Android Studio实现简单的QQ应用全部内容,希望文章能够帮你解决Android Studio实现简单的QQ应用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)