概述
当前中国最主流的及时通讯工具之一腾讯,经历过这么多年的更迭,其代码繁杂度可想而知,我闲着没事,就仿造手机的布局写了个山寨货,只是长得像而已,肚子里还没装货,并没有实现那些繁杂的功能,不然,我一个人也必然做不到,要实现功能,就看我闲不闲了。
演示结果:
怎么样,乍一看是不是挺像啊?我并没有实现圆形头像,因为我觉得麻烦。
代码如下:
主活动:
主活动中用一个fragment的adapter加载三个fragment,这三个fragment分别显示演示结果中的三个页面。然后用一个ViewPager(v4包的)加载这个adpter,给ViewPager加监听,当滑动时翻页。给RadioGroup加点击事件,当RadioButton的Checked项变化时,页面也将发生变化。
public class MainActivity extends FragmentActivity implements RadioGroup.OnCheckedChangeListener {
private RadioGroup mRadioGroup; private FragmentManager mFragmentManager; private FragmentTransaction mTransaction; //翻页变化项 private LinearLayout mFirstLinearLayout; private EditText mEditSearch; private TextView mTextState; private TextView mTextMore; private ImageView mImageTitleRight; private MyFragment1 myFragment1; private MyFragment2 myFragment2; private MyFragment3 myFragment3; private ViewPager mViewPager; private MyFragmentPagerAdapter myAdapter; private List
mFragments;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); mRadioGroup = (RadioGroup)findViewById(R.id.radio_group); mViewPager = (ViewPager) findViewById(R.id.my_view_pager); mFirstLinearLayout = (LinearLayout) findViewById(R.id.linearlayout_first); mEditSearch = (EditText) findViewById(R.id.edit_search); mTextState = (TextView) findViewById(R.id.text_state); mTextMore = (TextView) findViewById(R.id.text_more); mImageTitleRight = (ImageView) findViewById(R.id.image_title_right); mFragmentManager = getSupportFragmentManager(); myFragment1 =
new MyFragment1(); myFragment2 =
new MyFragment2(); myFragment3 =
new MyFragment3(); mFragments =
new ArrayList<>(); mFragments.add(myFragment1); mFragments.add(myFragment2); mFragments.add(myFragment3); myAdapter =
new MyFragmentPagerAdapter(mFragments,mFragmentManager); mViewPager.setAdapter(myAdapter); mRadioGroup.setOnCheckedChangeListener(
this); mViewPager.addOnPageChangeListener(
new ViewPager.OnPageChangeListener() {
@Override
public
void
onPageScrolled(
int position,
float positionOffset,
int positionOffsetPixels) { }
@Override
public
void
onPageSelected(
int position) {
switch (position) {
case
0:mRadioGroup.check(R.id.radio_button_msg); mEditSearch.setHint(
"搜索"); mTextState.setVisibility(View.GONE); mTextMore.setVisibility(View.GONE); mImageTitleRight.setVisibility(View.VISIBLE); mFirstLinearLayout.setVisibility(View.VISIBLE);
break;
case
1:mRadioGroup.check(R.id.radio_button_man); mEditSearch.setHint(
"搜索"); mTextState.setText(
"联系人"); mTextMore.setText(
"添加"); mTextState.setVisibility(View.VISIBLE); mTextMore.setVisibility(View.VISIBLE); mImageTitleRight.setVisibility(View.GONE); mFirstLinearLayout.setVisibility(View.GONE);
break;
case
2:mRadioGroup.check(R.id.radio_button_act); mEditSearch.setHint(
"搜索电影/音乐/商品"); mTextState.setText(
"动态"); mTextMore.setText(
"更多"); mTextState.setVisibility(View.VISIBLE); mTextMore.setVisibility(View.VISIBLE); mImageTitleRight.setVisibility(View.GONE); mFirstLinearLayout.setVisibility(View.GONE);
break;
default:
break; } }
@Override
public
void
onPageScrollStateChanged(
int state) { } }); }
@Override
public
void
onCheckedChanged(RadioGroup group,
int checkedId) {
switch (checkedId){
case R.id.radio_button_msg: mViewPager.setCurrentItem(
0);
break;
case R.id.radio_button_man: mViewPager.setCurrentItem(
1);
break;
case R.id.radio_button_act: mViewPager.setCurrentItem(
2);
break;
default:
break; } } }
建一个fragment包存放三个Fragment:
完成第一个页面的加载,其中包括一个ListView
public class MyFragment1 extends Fragment {
private ListView mMesaageList; private MsgListAdapter mMsgListAdapter; private List
mMsgs;
@Nullable
@Override
public View
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_1,
null); mMesaageList = (ListView) view.findViewById(R.id.listview_msg); initMsgs(); mMsgListAdapter =
new MsgListAdapter(inflater,mMsgs); mMesaageList.setAdapter(mMsgListAdapter);
return view; }
public
void
initMsgs(){ mMsgs =
new ArrayList<>(); Message message =
new Message(
"琪货",R.mipmap.mengqi,
"你是日美!",
"下午6:14"); Message message1 =
new Message(
"凯子",R.mipmap.yukai,
"[图片]",
"上午10:35"); Message message2 =
new Message(
"萝卜",R.mipmap.luobu,
"萝卜:我又长胖了",
"上午8:25"); Message message3 =
new Message(
"学兵",R.mipmap.xuebing,
"学兵:你怎么这么帅,比我都帅",
"昨天"); Message message4 =
new Message(
"旺旺",R.mipmap.wangwang,
"再莫齿我",
"星期四"); Message message5 =
new Message(
"海萌",R.mipmap.haimeng,
"海萌:我想吃,给我带两只烤鸭",
"星期三"); Message message6 =
new Message(
"涛涛",R.mipmap.litao,
"涛涛:我长这么帅怎么办啊?",
"星期三"); mMsgs.add(message); mMsgs.add(message1); mMsgs.add(message2); mMsgs.add(message3); mMsgs.add(message4); mMsgs.add(message5); mMsgs.add(message6); } }
第二个页面加载有点麻烦,因为有两个ExpandebleListView一个是设备的另一个是联系人的
public class MyFragment2 extends Fragment {
private ExpandableListView mRelativityExpList; private ExpandableListView mPhoneDeviceExpList; private List
mRelativityItems;
private RelativetyAdapter mAdapter;
private List
mDeviceItems;
private SecondMyPhoneExpAdapter mPhoneExpAdapter;
@Nullable
@Override
public View
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment2,
null); mRelativityExpList = (ExpandableListView) view.findViewById(R.id.expanded_list_); mPhoneDeviceExpList = (ExpandableListView) view.findViewById(R.id.expanded_list_mypone); initRelativities(); mAdapter =
new RelativetyAdapter(mRelativityItems,inflater); mRelativityExpList.setAdapter(mAdapter); initDevices(); mPhoneExpAdapter =
new SecondMyPhoneExpAdapter(mDeviceItems,inflater); mPhoneDeviceExpList.setAdapter(mPhoneExpAdapter);
return view; }
private
void
initDevices() { mDeviceItems =
new ArrayList<>(); RelativetyItem relativetyItem1 =
new RelativetyItem(
"我的设备",
"2/2"); RelativetyItem relativetyItem2 =
new RelativetyItem(
"手机通讯录",
"1/3"); List
devices =
new ArrayList<>(); List
peoples =
new ArrayList<>(); ContactsPeople people1 =
new ContactsPeople(
"我的电脑",
"无需数据线,手机轻松传文件到电脑",
"[在线]",R.mipmap.dod,
""); ContactsPeople people2 =
new ContactsPeople(
"搜索新设备",
"搜索附近的设备,用轻松连接设备",
"[在线]",R.mipmap.doc,
""); ContactsPeople people3 =
new ContactsPeople(
"乔布斯",
"",
"[已故]",R.mipmap.qiaobusi,
"-"); ContactsPeople people4 =
new ContactsPeople(
"比尔.盖茨",
"",
"",R.mipmap.bier,
"4G"); ContactsPeople people5 =
new ContactsPeople(
"马云",
"",
"[在线]",R.mipmap.mayun,
"4G"); devices.add(people1); devices.add(people2); peoples.add(people3); peoples.add(people4); peoples.add(people5); relativetyItem1.setPeoples(devices); relativetyItem2.setPeoples(peoples); mDeviceItems.add(relativetyItem1); mDeviceItems.add(relativetyItem2); }
private
void
initRelativities() { mRelativityItems =
new ArrayList<>(); RelativetyItem relativetyItem1 =
new RelativetyItem(
"老师",
"1/1"); RelativetyItem relativetyItem2 =
new RelativetyItem(
"朋友",
"3/5"); RelativetyItem relativetyItem3 =
new RelativetyItem(
"同学",
"1/2"); RelativetyItem relativetyItem4 =
new RelativetyItem(
"黑名单",
"1/1"); List
peoples1 =
new ArrayList<>(); List
peoples2 =
new ArrayList<>(); List
peoples3 =
new ArrayList<>(); List
peoples4 =
new ArrayList<>(); ContactsPeople people1 =
new ContactsPeople(
"梦琪",
"我是一个二比",
"[在线]",R.mipmap.mengqi,
"4G"); ContactsPeople people2 =
new ContactsPeople(
"凯子",
"就是这么不羁",
"",R.mipmap.yukai,
"3G"); ContactsPeople people3 =
new ContactsPeople(
"学兵",
"发表图片",
"[在线]",R.mipmap.xuebing,
"3G"); ContactsPeople people4 =
new ContactsPeople(
"旺旺",
"此身,已许国,再难许卿",
"[在线]",R.mipmap.wangwang,
"2G"); ContactsPeople people5 =
new ContactsPeople(
"萝卜",
"更新了相册",
"",R.mipmap.luobu,
"3G"); ContactsPeople people6 =
new ContactsPeople(
"海萌",
"我要吃哦",
"[在线]",R.mipmap.haimeng,
"3G"); ContactsPeople people7 =
new ContactsPeople(
"涛涛",
"我很帅,对",
"",R.mipmap.litao,
"3G"); ContactsPeople people8 =
new ContactsPeople(
"老师",
"为什么我这么帅",
"[在线]",R.mipmap.laoshi,
"4G"); ContactsPeople people9 =
new ContactsPeople(
"戈乌龟",
"",
"",R.mipmap.gefei,
"3G"); peoples1.add(people1); peoples1.add(people2); peoples1.add(people3); peoples1.add(people4); peoples1.add(people5); peoples2.add(people6); peoples2.add(people7); peoples3.add(people8); peoples4.add(people9); relativetyItem1.setPeoples(peoples3); relativetyItem2.setPeoples(peoples1); relativetyItem3.setPeoples(peoples2); relativetyItem4.setPeoples(peoples4); mRelativityItems.add(relativetyItem1); mRelativityItems.add(relativetyItem2); mRelativityItems.add(relativetyItem3); mRelativityItems.add(relativetyItem4); } }
第三个页面有两个ListView
public class MyFragment3 extends Fragment {
private ListView listViewUp; private ListView listViewDown; private ThirdPageListAdapter mAdapterUp; private ThirdPageListAdapter mAdapterDown; private List
mThreePageItemsUp;
private List
mThreePageItemsDown;
@Nullable
@Override
public View
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment3,
null); listViewUp = (ListView) view.findViewById(R.id.list_play); listViewDown = (ListView) view.findViewById(R.id.list_service); initDataUp(); mAdapterUp =
new ThirdPageListAdapter(mThreePageItemsUp,inflater); listViewUp.setAdapter(mAdapterUp); initDataDown(); mAdapterDown =
new ThirdPageListAdapter(mThreePageItemsDown,inflater); listViewDown.setAdapter(mAdapterDown);
return view; }
private
void
initDataDown() { mThreePageItemsDown =
new ArrayList<>();
//ThreePageItem item1 = new ThreePageItem("评书",R.mipmap.dyf);
//ThreePageItem item3 = new ThreePageItem("购物",R.mipmap.main_icon01); ThreePageItem item1 =
new ThreePageItem(
"音乐",R.mipmap.music); ThreePageItem item2 =
new ThreePageItem(
"视频",R.mipmap.efp); ThreePageItem item3 =
new ThreePageItem(
"PS",R.mipmap.ps); mThreePageItemsDown.add(item1); mThreePageItemsDown.add(item2); mThreePageItemsDown.add(item3); }
private
void
initDataUp() { mThreePageItemsUp =
new ArrayList<>(); ThreePageItem item1 =
new ThreePageItem(
"美食",R.mipmap.dyf); ThreePageItem item2 =
new ThreePageItem(
"购物",R.mipmap.main_icon01); ThreePageItem item3 =
new ThreePageItem(
"游戏",R.mipmap.youxipng); mThreePageItemsUp.add(item1); mThreePageItemsUp.add(item2); mThreePageItemsUp.add(item3); } }
建一个adapter包存放所有的adapter
加载第一个页面所有信息条目的View
public class MsgListAdapter extends BaseAdapter {
private LayoutInflater mInflater; private List
mMsgs;
public
MsgListAdapter(LayoutInflater mInflater, List
mMsgs) {
this.mInflater = mInflater;
this.mMsgs = mMsgs; }
@Override
public
int
getCount() {
return mMsgs.size(); }
@Override
public Object
getItem(
int position) {
return position; }
@Override
public
long
getItemId(
int position) {
return position; }
@Override
public View
getView(
int position, View convertView, ViewGroup parent) { ViewHolder vh =
null;
if(convertView==
null){ convertView = mInflater.inflate(R.layout.listview_msg_item,
null); vh =
new ViewHolder(); vh.msgImageView = (ImageView) convertView.findViewById(R.id.image_msg); vh.msgUserNameText = (TextView) convertView.findViewById(R.id.text_msg_username); vh.msgWordsText = (TextView) convertView.findViewById(R.id.text_msg_words); vh.msgTimeText = (TextView) convertView.findViewById(R.id.text_msg_time); convertView.setTag(vh); }
else{ vh = (ViewHolder) convertView.getTag(); } Message message = mMsgs.get(position); vh.msgImageView.setImageResource(message.getImageId()); vh.msgUserNameText.setText(message.getUserName()); vh.msgWordsText.setText(message.getMsg()); vh.msgTimeText.setText(message.getTime());
return convertView; }
private
class ViewHolder{
ImageView msgImageView; TextView msgUserNameText; TextView msgWordsText; TextView msgTimeText; } }
三个Fragment的adapter
public class MyFragmentPagerAdapter extends FragmentPagerAdapter {
private List
mFragments;
public
MyFragmentPagerAdapter(List
mFragments,FragmentManager fm) {
super(fm);
this.mFragments = mFragments; }
@Override
public Fragment
getItem(
int position) {
return mFragments.get(position); }
@Override
public
int
getCount() {
return mFragments.size(); } }
第二个页面设备ExpandebleListView的Adapter
public class RelativetyAdapter extends BaseExpandableListAdapter {
private List
mRlaRelativetyItems;
private LayoutInflater mInflater;
public
RelativetyAdapter(List
mRlaRelativetyItems, LayoutInflater mInflater) {
this.mRlaRelativetyItems = mRlaRelativetyItems;
this.mInflater = mInflater; }
@Override
public
int
getGroupCount() {
return mRlaRelativetyItems.size(); }
@Override
public
int
getChildrenCount(
int groupPosition) {
return mRlaRelativetyItems.get(groupPosition).getPeoples().size(); }
@Override
public Object
getGroup(
int groupPosition) {
return groupPosition; }
@Override
public Object
getChild(
int groupPosition,
int childPosition) {
return childPosition; }
@Override
public
long
getGroupId(
int groupPosition) {
return groupPosition; }
@Override
public
long
getChildId(
int groupPosition,
int childPosition) {
return childPosition; }
@Override
public
boolean
hasStableIds() {
return
false; }
@Override
public View
getGroupView(
int groupPosition,
boolean isExpanded, View convertView, ViewGroup parent) { GroupViewHolder gvh =
null;
if (convertView ==
null) { convertView = mInflater.inflate(R.layout.relativety_item,
null); gvh =
new GroupViewHolder(); gvh.groupName = (TextView) convertView.findViewById(R.id.text_relative_group_name); gvh.peopleNum = (TextView) convertView.findViewById(R.id.text_relative_people_num); convertView.setTag(gvh); }
else { gvh = (GroupViewHolder) convertView.getTag(); } RelativetyItem relativetyItem = mRlaRelativetyItems.get(groupPosition); gvh.groupName.setText(relativetyItem.getGroupName().toString()); gvh.peopleNum.setText(relativetyItem.getPeopleNum().toString());
return convertView; }
@Override
public View
getChildView(
int groupPosition,
int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) { ChildViewHolder cvh =
null;
if(convertView==
null) { cvh =
new ChildViewHolder(); convertView = mInflater.inflate(R.layout.exp_people_item,
null); cvh.userName = (TextView) convertView.findViewById(R.id.text_contacts_username); cvh.StateMessage = (TextView) convertView.findViewById(R.id.text_contacts_user_msg_state); cvh.userState = (TextView) convertView.findViewById(R.id.text_contacts_user_state); cvh.userImage = (ImageView) convertView.findViewById(R.id.image_contacts_user); cvh.xGMsg = (TextView) convertView.findViewById(R.id.text_contacts_xG); convertView.setTag(cvh); }
else{ cvh = (ChildViewHolder) convertView.getTag(); } ContactsPeople people = mRlaRelativetyItems.get(groupPosition).getPeoples().get(childPosition); cvh.userName.setText(people.getUserName()); cvh.StateMessage.setText(people.getStateMessage()); cvh.userState.setText(people.getUserState()); cvh.userImage.setImageResource(people.getImageId()); cvh.xGMsg.setText(people.getxGMsg());
return convertView; }
@Override
public
boolean
isChildSelectable(
int groupPosition,
int childPosition) {
return
true; }
private
class GroupViewHolder {
TextView groupName; TextView peopleNum; }
private
class ChildViewHolder {
TextView userName; TextView StateMessage; TextView userState; ImageView userImage; TextView xGMsg; } }
第二个页面的联系人ExpandableListView的adapter
public class SecondMyPhoneExpAdapter extends BaseExpandableListAdapter{
private List
mRlaRelativetyItems;
private LayoutInflater mInflater;
public
SecondMyPhoneExpAdapter(List
mRlaRelativetyItems, LayoutInflater mInflater) {
this.mRlaRelativetyItems = mRlaRelativetyItems;
this.mInflater = mInflater; }
@Override
public
int
getGroupCount() {
return mRlaRelativetyItems.size(); }
@Override
public
int
getChildrenCount(
int groupPosition) {
return mRlaRelativetyItems.get(groupPosition).getPeoples().size(); }
@Override
public Object
getGroup(
int groupPosition) {
return groupPosition; }
@Override
public Object
getChild(
int groupPosition,
int childPosition) {
return childPosition; }
@Override
public
long
getGroupId(
int groupPosition) {
return groupPosition; }
@Override
public
long
getChildId(
int groupPosition,
int childPosition) {
return childPosition; }
@Override
public
boolean
hasStableIds() {
return
false; }
@Override
public View
getGroupView(
int groupPosition,
boolean isExpanded, View convertView, ViewGroup parent) { GroupViewHolder gvh =
null;
if (convertView ==
null) { convertView = mInflater.inflate(R.layout.relativety_item,
null); gvh =
new GroupViewHolder(); gvh.groupName = (TextView) convertView.findViewById(R.id.text_relative_group_name); gvh.peopleNum = (TextView) convertView.findViewById(R.id.text_relative_people_num); convertView.setTag(gvh); }
else { gvh = (GroupViewHolder) convertView.getTag(); } RelativetyItem relativetyItem = mRlaRelativetyItems.get(groupPosition); gvh.groupName.setText(relativetyItem.getGroupName().toString()); gvh.peopleNum.setText(relativetyItem.getPeopleNum().toString());
return convertView; }
@Override
public View
getChildView(
int groupPosition,
int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) { ChildViewHolder cvh =
null;
if(convertView==
null) { cvh =
new ChildViewHolder(); convertView = mInflater.inflate(R.layout.exp_device_item,
null); cvh.userName = (TextView) convertView.findViewById(R.id.text_contacts_username); cvh.StateMessage = (TextView) convertView.findViewById(R.id.text_contacts_user_msg_state); cvh.userState = (TextView) convertView.findViewById(R.id.text_contacts_user_state); cvh.userImage = (ImageView) convertView.findViewById(R.id.image_contacts_user); cvh.xGMsg = (TextView) convertView.findViewById(R.id.text_contacts_xG); convertView.setTag(cvh); }
else{ cvh = (ChildViewHolder) convertView.getTag(); } ContactsPeople people = mRlaRelativetyItems.get(groupPosition).getPeoples().get(childPosition); cvh.userName.setText(people.getUserName()); cvh.StateMessage.setText(people.getStateMessage()); cvh.userState.setText(people.getUserState()); cvh.userImage.setImageResource(people.getImageId()); cvh.xGMsg.setText(people.getxGMsg());
return convertView; }
@Override
public
boolean
isChildSelectable(
int groupPosition,
int childPosition) {
return
true; }
private
class GroupViewHolder {
TextView groupName; TextView peopleNum; }
private
class ChildViewHolder {
TextView userName; TextView StateMessage; TextView userState; ImageView userImage; TextView xGMsg; } }
第三个页面两个ListView的adapter
public class ThirdPageListAdapter extends BaseAdapter {
private List
mThreePageItems;
private LayoutInflater mInflater;
public
ThirdPageListAdapter(List
mThreePageItems, LayoutInflater mInflater) {
this.mThreePageItems = mThreePageItems;
this.mInflater = mInflater; }
@Override
public
int
getCount() {
return mThreePageItems.size(); }
@Override
public Object
getItem(
int position) {
return position; }
@Override
public
long
getItemId(
int position) {
return position; }
@Override
public View
getView(
int position, View convertView, ViewGroup parent) { ViewHolder viewHolder =
null;
if(convertView==
null){ convertView = mInflater.inflate(R.layout.third_page_list_item,
null); viewHolder =
new ViewHolder(); viewHolder.thirdPageImage = (ImageView) convertView.findViewById(R.id.image_third_page); viewHolder.thirdPageText = (TextView) convertView.findViewById(R.id.text_third_page); convertView.setTag(viewHolder); }
else{ viewHolder = (ViewHolder) convertView.getTag(); } ThreePageItem item = mThreePageItems.get(position); viewHolder.thirdPageImage.setImageResource(item.getImageId()); viewHolder.thirdPageText.setText(item.getName());
return convertView; }
public
class ViewHolder{
ImageView thirdPageImage; TextView thirdPageText; } }
建立一个model包存放所有的model
第一页加载信息的model
public class Message {
private String userName; private int imageId; private String msg; private String time; public Message(String userName, int imageId, String msg, String time) { this.userName = userName; this.imageId = imageId; this.msg = msg; this.time = time; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public int getImageId() { return imageId; } public void setImageId(int imageId) { this.imageId = imageId; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getTime() { return time; } public void setTime(String time) { this.time = time; } }
第二页存放联系人属性的model
public class ContactsPeople {
private String userName; private String stateMessage; private String userState; private int imageId; private String xGMsg; public ContactsPeople(String userName, String stateMessage, String userState, int imageId, String xGMsg) { this.userName = userName; this.stateMessage = stateMessage; this.userState = userState; this.imageId = imageId; this.xGMsg = xGMsg; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getStateMessage() { return stateMessage; } public void setStateMessage(String stateMessage) { this.stateMessage = stateMessage; } public String getUserState() { return userState; } public void setUserState(String userState) { this.userState = userState; } public int getImageId() { return imageId; } public void setImageId(int imageId) { this.imageId = imageId; } public String getxGMsg() { return xGMsg; } public void setxGMsg(String xGMsg) { this.xGMsg = xGMsg; } }
第二页Expandable父组件的model
public class RelativetyItem {
private String groupName; private String peopleNum; private List
peoples;
public
RelativetyItem(String groupName, String peopleNum) {
this.groupName = groupName;
this.peopleNum = peopleNum; }
public String
getGroupName() {
return groupName; }
public
void
setGroupName(String groupName) {
this.groupName = groupName; }
public String
getPeopleNum() {
return peopleNum; }
public
void
setPeopleNum(String peopleNum) {
this.peopleNum = peopleNum; }
public List
getPeoples() {
return peoples; }
public
void
setPeoples(List
peoples) {
this.peoples = peoples; } }
第二页设备子组件的model
public class PhoneItem {
private String name; public PhoneItem(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
第三页两个ListView的每条View的model
public class ThreePageItem {
private String name; private int imageId; public ThreePageItem(String name, int imageId) { this.name = name; this.imageId = imageId; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getImageId() { return imageId; } public void setImageId(int imageId) { this.imageId = imageId; } }
重点是布局:
layout目录下:
activity_main:
<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" android:gravity="center_horizontal" android:orientation="vertical"> <RelativeLayout android:id="@+id/layout_title" android:layout_width="match_parent" android:layout_height="70dp" android:background="@color/blue"> <ImageView android:id="@+id/image_title_left" android:layout_width="33dp" android:layout_height="33dp" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:src="@mipmap/head_logo"/> <ImageView android:id="@+id/image_title_right" android:layout_width="30dp" android:layout_height="30dp" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="10dp" android:layout_marginRight="10dp" android:src="@mipmap/classify_normal"/> <TextView android:id="@+id/text_state" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:layout_marginBottom="10dp" android:gravity="center" android:textSize="19dp" android:textColor="@color/white" android:visibility="gone" android:text="联系人"/> <TextView android:id="@+id/text_more" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="10dp" android:layout_marginRight="10dp" android:gravity="center" android:textSize="16dp" android:textColor="@color/white" android:visibility="gone" android:text="联系人"/> <LinearLayout android:id="@+id/linearlayout_first" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:gravity="center" android:orientation="horizontal"> <RadioGroup android:id="@+id/radio_group_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:checkedButton="@+id/radio_button_meessage"> <RadioButton android:id="@+id/radio_button_meessage" android:layout_width="60dp" android:layout_height="30dp" android:background="@drawable/title_button_left_state" android:textColor="@color/blue" android:button="@null" android:gravity="center" android:textSize="14dp" android:text="消息"/> <RadioButton android:id="@+id/radio_button_phone" android:layout_width="60dp" android:layout_height="30dp" android:background="@drawable/title_button_right_state" android:textColor="@color/white" android:button="@null" android:gravity="center" android:textSize="14dp" android:text="电话"/>
RadioGroup>
LinearLayout>
RelativeLayout> <EditText android:id="@+id/edit_search" android:layout_width="match_parent" android:layout_height="30dp" android:layout_margin="8dp" android:layout_below="@+id/layout_title" android:gravity="center" android:textSize="13dp" android:background="@drawable/input_bg" android:focusableInTouchMode="false" android:hint="搜索" android:drawableStart="@mipmap/a_icon_search"/> <android.support.v4.view.ViewPager android:id="@+id/my_view_pager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:layout_below="@+id/edit_search">
android.support.v4.view.ViewPager> <RadioGroup android:id="@+id/radio_group" android:layout_width="match_parent" android:layout_height="58dp" android:layout_alignParentBottom="true" android:checkedButton="@+id/radio_button_msg" android:background="@drawable/bottom" android:gravity="center" android:orientation="horizontal"> <RadioButton android:id="@+id/radio_button_msg" android:layout_width="@dimen/bottom_image_size" android:layout_height="@dimen/bottom_image_size" android:background="@drawable/log2_state" android:button="@null"/> <RadioButton android:id="@+id/radio_button_man" android:layout_width="@dimen/bottom_image_size" android:layout_height="@dimen/bottom_image_size" android:layout_marginLeft="70dp" android:layout_marginRight="70dp" android:background="@drawable/log1_state" android:button="@null"/> <RadioButton android:id="@+id/radio_button_act" android:layout_width="@dimen/bottom_image_size" android:layout_height="@dimen/bottom_image_size" android:background="@drawable/log3_state" android:button="@null"/>
RadioGroup>
LinearLayout>
exp_device_item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white" android:orientation="horizontal" android:padding="3dp"> <ImageView android:id="@+id/image_contacts_user" android:layout_width="37dp" android:layout_height="37dp" android:layout_margin="2dp" android:src="@mipmap/mengqi"/> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center_vertical" android:padding="2dp" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:padding="2dp"> <TextView android:id="@+id/text_contacts_username" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="凯子" android:textColor="@color/black" android:textSize="15dp"/> <TextView android:id="@+id/text_contacts_xG" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:textSize="12dp" android:text="3G"/>
RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical"> android:gravity="center_vertical"> <TextView android:id="@+id/text_contacts_user_state" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:gravity="center" android:layout_toRightOf="@+id/image_linear" android:textSize="11dp" android:text="[在线]"/> <TextView android:id="@+id/text_contacts_user_msg_state" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="5dp" android:layout_toRightOf="@+id/text_contacts_user_state" android:textSize="11dp" android:text="感谢人民,感谢党"/>
RelativeLayout>
LinearLayout>
LinearLayout>
exp_people_item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white" android:orientation="horizontal" android:padding="3dp"> <ImageView android:id="@+id/image_contacts_user" android:layout_width="37dp" android:layout_height="37dp" android:layout_margin="2dp" android:src="@mipmap/mengqi"/> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center_vertical" android:padding="2dp" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:padding="2dp"> <TextView android:id="@+id/text_contacts_username" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="凯子" android:textColor="@color/contacts_user_name_color" android:textSize="15dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginTop="2dp" android:layout_toRightOf="@+id/text_contacts_username" android:background="#ff0000" android:paddingLeft="1dp" android:paddingRight="1dp" android:text="VIP" android:textColor="@color/white" android:textSize="10dp"/> <TextView android:id="@+id/text_contacts_xG" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:textSize="12dp" android:text="3G"/>
RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical"> <LinearLayout android:id="@+id/image_linear" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="1dp"> <ImageView android:layout_width="11dp" android:layout_height="11dp" android:layout_marginLeft="1dp" android:layout_marginRight="1dp" android:layout_toRightOf="@+id/text_user_net_state" android:src="@mipmap/eek"/> <ImageView android:layout_width="11dp" android:layout_height="11dp" android:layout_marginRight="1dp" android:layout_toRightOf="@+id/text_user_msg" android:src="@mipmap/qb_group_upload_select_photo"/>
LinearLayout> <TextView android:id="@+id/text_contacts_user_state" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:gravity="center" android:layout_toRightOf="@+id/image_linear" android:textSize="11dp" android:text="[在线]"/> <TextView android:id="@+id/text_contacts_user_msg_state" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="5dp" android:layout_toRightOf="@+id/text_contacts_user_state" android:textSize="11dp" android:text="感谢人民,感谢党"/>
RelativeLayout>
LinearLayout>
LinearLayout>
fragment_1:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/fragment_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableLeft="@mipmap/eno" android:drawableRight="@mipmap/jzu" android:textSize="14dp" android:textColor="@color/black" android:text="@string/no_net_warn" android:padding="8dp" android:gravity="center_vertical" android:background="@color/no_net_title_color"/> <ListView android:id="@+id/listview_msg" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white">
ListView>
LinearLayout>
fragment2:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:padding="10dp" android:background="@color/white"> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:orientation="vertical"> <ImageView android:layout_width="@dimen/medium_image_size" android:layout_height="@dimen/medium_image_size" android:src="@mipmap/header_icon"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:textSize="14dp" android:text="新朋友" android:textColor="@color/black"/>
LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:orientation="vertical"> <ImageView android:layout_width="@dimen/title_image_size" android:layout_height="@dimen/title_image_size" android:src="@mipmap/a_merchant_04"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:textSize="14dp" android:text="特别关心" android:textColor="@color/black"/>
LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:orientation="vertical"> <ImageView android:layout_width="@dimen/title_image_size" android:layout_height="@dimen/title_image_size" android:src="@mipmap/a_main_icon03"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:textSize="14dp" android:text="群组" android:textColor="@color/black"/>
LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:orientation="vertical"> <ImageView android:layout_width="@dimen/title_image_size" android:layout_height="@dimen/title_image_size" android:src="@mipmap/nyzs"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:textSize="14dp" android:text="公众号" android:textColor="@color/black"/>
LinearLayout>
LinearLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:textSize="11dp" android:text="我的手机"/> <ExpandableListView android:id="@+id/expanded_list_mypone" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white">
ExpandableListView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:textSize="11dp" android:text="好友"/> <ExpandableListView android:id="@+id/expanded_list_" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white">
ExpandableListView>
LinearLayout>
fragment3:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white" android:gravity="center_vertical" android:padding="8dp"> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:orientation="vertical"> <ImageView android:layout_width="@dimen/title_image_size" android:layout_height="@dimen/title_image_size" android:src="@mipmap/eek"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:text="好友动态" android:textSize="14dp" android:textColor="@color/black"/>
LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:orientation="vertical"> <ImageView android:layout_width="@dimen/title_image_size" android:layout_height="@dimen/title_image_size" android:src="@mipmap/egz"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:text="附近" android:textSize="14dp" android:textColor="@color/black"/>
LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:orientation="vertical"> <ImageView android:layout_width="@dimen/title_image_size" android:layout_height="@dimen/title_image_size" android:src="@mipmap/dec"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:text="兴趣部落" android:textSize="14dp" android:textColor="@color/black"/>
LinearLayout>
LinearLayout> <ListView android:id="@+id/list_play" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="25dp" android:background="@color/white">
ListView> <ListView android:id="@+id/list_service" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="25dp" android:background="@color/white">
ListView>
LinearLayout>
listview_msg_item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white" android:orientation="horizontal" android:padding="2dp"> <ImageView android:id="@+id/image_msg" android:layout_width="45dp" android:layout_height="45dp" android:layout_margin="5dp" android:src="@mipmap/yukai"/> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="3dp"> <TextView android:id="@+id/text_msg_username" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="凯子" android:textColor="@color/black" android:textSize="16dp"/> <TextView android:id="@+id/text_msg_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:textSize="13dp" android:text="下午4:31"/>
RelativeLayout> <TextView android:id="@+id/text_msg_words" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="3dp" android:layout_marginLeft="3dp" android:layout_marginRight="3dp" android:textSize="13dp" android:text="你们都是日美"/>
LinearLayout>
LinearLayout>
relativety_item:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/text_relative_group_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:paddingBottom="11dp" android:paddingTop="11dp" android:paddingLeft="35dp" android:textSize="16dp" android:textColor="@color/black" android:text="亲人"/> <TextView android:id="@+id/text_relative_people_num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:paddingRight="12dp" android:textSize="12dp" android:text="1/2"/>
RelativeLayout>
third_page_list_item:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="8dp"> <ImageView android:id="@+id/image_third_page" android:layout_width="28dp" android:layout_height="28dp" android:src="@mipmap/dhv"/> <TextView android:id="@+id/text_third_page" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/image_third_page" android:layout_centerVertical="true" android:paddingLeft="14dp" android:textSize="16dp" android:textColor="@color/black" android:text="购物"/> <ImageView android:layout_width="16dp" android:layout_height="16dp" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:layout_marginRight="20dp" android:src="@mipmap/eou"/>
RelativeLayout>
drawable目录下:
bottom:
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#e0f0f0">
solid> <stroke android:color="#40e0d0" android:width="0.5dp">
stroke>
shape>
input_bg
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="5dp">
corners> <solid android:color="@color/white">
solid>
shape>
log1_state:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@mipmap/log1_checked" android:state_checked="true">
item> <item android:drawable="@mipmap/log1_nomal">
item>
selector>
log2_state:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@mipmap/log2_checked" android:state_checked="true">
item> <item android:drawable="@mipmap/log2_nomal">
item>
selector>
log3_state:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@mipmap/log3_checked" android:state_checked="true">
item> <item android:drawable="@mipmap/log3_nomal">
item>
selector>
title_button_bg:
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:bottomLeftRadius="@dimen/title_bt_color" android:topLeftRadius="@dimen/title_bt_color">
corners> <solid android:color="@color/blue">
solid> <stroke android:color="@color/white" android:width="@dimen/mini_width">
stroke>
shape>
title_button_pressed_bg:
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:bottomLeftRadius="@dimen/title_bt_color" android:topLeftRadius="@dimen/title_bt_color">
corners> <solid android:color="@color/white">
solid> <stroke android:width="@dimen/mini_width" android:color="@color/white">
stroke>
shape>
title_button_left_state:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/title_button_pressed_bg" android:state_checked="true">
item> <item android:drawable="@drawable/title_button_bg">
item>
selector>
title_button_right_bg
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:bottomRightRadius="@dimen/title_bt_color" android:topRightRadius="@dimen/title_bt_color">
corners> <solid android:color="@color/blue">
solid> <stroke android:color="@color/white" android:width="@dimen/mini_width">
stroke>
shape>
title_button_right_pressed_bg:
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:bottomRightRadius="@dimen/title_bt_color" android:topRightRadius="@dimen/title_bt_color">
corners> <solid android:color="@color/white">
solid> <stroke android:color="@color/white" android:width="@dimen/mini_width">
stroke>
shape>
title_button_right_state:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/title_button_right_pressed_bg" android:state_checked="true">
item> <item android:drawable="@drawable/title_button_right_bg">
item>
selector>
values下的文件:
我没有用颜色提取器,所以配色不太准。
colors:
<resources> <color name="black">#
color> <color name="white">#fefefe
color> <color name="blue">#87ceef
color> <color name="no_net_title_color">#90f490
color> <color name="contacts_user_name_color">#ff4500
color>
resources>
dimens
<resources>
<dimen name="activity_horizontal_margin">16dp
dimen> <dimen name="activity_vertical_margin">16dp
dimen> <dimen name="title_bt_color">12dp
dimen> <dimen name="mini_width">1dp
dimen> <dimen name="title_image_size">40dp
dimen> <dimen name="bottom_image_size">60dp
dimen> <dimen name="medium_image_size">40dp
dimen>
resources>
此外,本来可以在style中设置自定义一个style,那样将会使代码更简约。
我们猿类工作压力大,很需要有自己的乐趣,于是乎,我开通了音乐人账号,以后的作品将会上传到我的音乐人小站上。如果这篇博客帮助到您,希望您能多关注,支持,鼓励我将创作进行下去,同时也祝你能在工作和生活乐趣两发面都能出彩!
网易云音乐人,直接打开客户端搜索音乐人 “星河河”
豆瓣音乐人地址:https://site.douban.com/chuxinghe/ 星河河
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/209604.html原文链接:https://javaforall.net
