转载请标明出处:http://blog.csdn.net/android_ls/article/details/9410055
声明:仿人人项目,所用所有图片资源都来源于其它Android移动应用,编写本应用的目的在于学习交流,如涉及侵权请告知,我会及时换掉用到的相关图片。
这一篇是基于前面的
Android仿人人客户端(v5.7.1)——点击左侧菜单栏中的Item切换视图
这篇博文,聊聊有关左侧菜单在实现过程中,我后面所做的修改。
一、实现过程中修改的部分。
1、在之前的左侧Item对象中,添加当前Item是否为选中项的属性,代码如下:
package com.everyone.android.entity;
import java.util.ArrayList;
/**
* 功能描述:左侧面板Item信息
* @author android_ls
*
*/
public class LeftPanelListItem {
private int id; // 唯一标识
private String name; // 操作项名称
private int drawableId; // 指示图标 #R.drawable.ic_launcher
private boolean selected; // 当前是否为选中项
private ArrayList<LeftPanelListItem> groups;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getDrawableId() {
return drawableId;
}
public void setDrawableId(int drawableId) {
this.drawableId = drawableId;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public ArrayList<LeftPanelListItem> getGroups() {
return groups;
}
public void setGroups(ArrayList<LeftPanelListItem> groups) {
this.groups = groups;
}
}
2、在
LeftPanelExListViewAdapter类的
public View getChildView(int groupPosition,int childPosition,boolean isLastChild, View convertView, ViewGroup parent) {}回调方法中添加如下处理:
if(listItem.isSelected()){
convertView.setBackgroundResource(R.drawable.menu_item_bg_sel);
viewHolder.groupName.setSelected(true);
} else {
convertView.setBackgroundResource(R.drawable.left_panel_item_selector);
viewHolder.groupName.setSelected(false);
}
3、修改ExpandableListView的
mExpandableListView.setOnChildClickListener(){}事件监听器中的处理,代码如下:
mExpandableListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
if (mOnSeletedListener == null) {
return false;
}
// 去掉上一次选中的项
mListItems.get(mGroupPosition).getGroups().get(mChildPosition).setSelected(false);
mGroupPosition = groupPosition;
mChildPosition = childPosition;
// 选中当前选择的项
mListItems.get(mGroupPosition).getGroups().get(mChildPosition).setSelected(true);
mExListViewAdapter.notifyDataSetChanged();
mOnSeletedListener.seletedChildView(groupPosition, childPosition);
return true;
}
});
4、修改二级菜单的selector(left_panel_item_selector.xml)配置文件如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/menu_item_bg_sel" android:state_selected="true"/>
<item android:drawable="@drawable/menu_item_background_down" android:state_focused="true"/>
<item android:drawable="@drawable/menu_item_background_down" android:state_pressed="true"/>
<item android:drawable="@drawable/menu_item_background_up"/>
</selector>
5、在每个view(新鲜事视图、消息视图和好友视图等)类中,提供 获取顶部导航栏中左侧Menu组件,代码如下:
/**
* 获取顶部左侧的menu组件
* @return
*/
public LinearLayout getMenuView() {
return topMenuNavbar.llShowMenu;
}
6、在
EveryoneActivity类中,
public class EveryoneActivityextends NetworkBaseActivityimplements View.OnClickListener, onSeletedListener {}
a.获取Menu组件并为其设置单击事件监听器
mFreshNewsLayout.getMenuView().setOnClickListener(this);
b.在单击事件处理器中添加如下代码:
@Override
public void onClick(View v) {
mSlideContainer.show();
}
二、运行后的效果图
LeftPanelLayout类源码:
package com.everyone.android.ui.leftpanel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.json.JSONException;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.everyone.android.R;
import com.everyone.android.api.AuthTokenManager;
import com.everyone.android.api.NetworkBaseActivity;
import com.everyone.android.bitmap.ImageLoader;
import com.everyone.android.callback.ParseCallback;
import com.everyone.android.callback.ResultCallback;
import com.everyone.android.entity.ImageInfo;
import com.everyone.android.entity.LeftPanelListItem;
import com.everyone.android.entity.UserBasicInfo;
import com.everyone.android.net.AsyncBaseRequest;
import com.everyone.android.net.AsyncHttpsPost;
import com.everyone.android.net.DefaultThreadPool;
import com.everyone.android.ui.user.PersonalHomepageActivity;
import com.everyone.android.utils.Constant;
import com.everyone.android.utils.DensityUtil;
import com.everyone.android.utils.LogUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
/**
* 功能描述:仿人人主界面之左侧面板
* @author android_ls
*
*/
public class LeftPanelLayout extends FrameLayout {
/**
* LOG打印标签
*/
private static final String TAG = LeftPanelLayout.class.getSimpleName();
/**
* 用户图标显示组件
*/
private ImageView ivUserIcon;
/**
* 用户名称显示组件
*/
private TextView tvNickname;
/**
* 可展开的ListView组件
*/
private ExpandableListView mExpandableListView;
/**
* ExpandableListView组件的数据适配器
*/
private LeftPanelExListViewAdapter mExListViewAdapter;
/**
* ExpandableListView组件的数据源
*/
private List<LeftPanelListItem> mListItems = new ArrayList<LeftPanelListItem>();
/**
* 分组名数组
*/
private String[] mGroupNames;
private onSeletedListener mOnSeletedListener;
private int mGroupPosition;
private int mChildPosition;
private NetworkBaseActivity mActivity;
private List<AsyncBaseRequest> mAsyncRequests;
private DefaultThreadPool mDefaultThreadPool;
private Handler mHandler;
private AuthTokenManager mAuthTokenManager;
protected ImageLoader mImageLoader;
public LeftPanelLayout(NetworkBaseActivity activity) {
super(activity);
mActivity = activity;
this.mAsyncRequests = activity.getAsyncRequests();
this.mDefaultThreadPool = activity.getDefaultThreadPool();
this.mHandler = activity.getHandler();
this.mAuthTokenManager = activity.getAuthTokenManager();
mImageLoader = new ImageLoader(activity);
setupViews();
}
public LeftPanelLayout(Context context, AttributeSet attrs) {
super(context, attrs);
setupViews();
}
private void setupViews() {
final LayoutInflater mInflater = LayoutInflater.from(getContext());
LinearLayout viewRoot = (LinearLayout) mInflater.inflate(R.layout.left_panel, null);
addView(viewRoot);
ivUserIcon = (ImageView) viewRoot.findViewById(R.id.iv_user_icon);
tvNickname = (TextView) viewRoot.findViewById(R.id.tv_nickname);
mExpandableListView = (ExpandableListView) viewRoot.findViewById(R.id.elv_list_view);
initialized();
}
private void initialized() {
Resources resources = this.getResources();
mGroupNames = resources.getStringArray(R.array.left_panel_group_names);
String[] firstGroupNames = resources.getStringArray(R.array.left_panel_first_group_names);
String[] secondGroupNames = resources.getStringArray(R.array.left_panel_second_group_names);
String[] threeGroupNames = resources.getStringArray(R.array.left_panel_group_three_names);
int[] firstGroupIcons = {
R.drawable.left_panel_item_newsfeed_icon_selector,
R.drawable.left_panel_item_message_icon_selector,
R.drawable.left_panel_item_chat_icon_selector,
R.drawable.left_panel_item_friends_icon_selector,
R.drawable.left_panel_item_search_icon_selector };
int[] secondGroupIcons = {
R.drawable.left_panel_item_location_icon_selector,
R.drawable.left_panel_item_mainpage_icon_selector,
R.drawable.left_panel_item_hot_icon_selector,
R.drawable.left_panel_item_apps_icon_selector };
int[] threeGroupIcons = {
R.drawable.left_panel_item_settings_icon_selector,
R.drawable.left_panel_item_layout_icon_selector };
addGroup(0, firstGroupNames, firstGroupIcons);
addGroup(1, secondGroupNames, secondGroupIcons);
addGroup(2, threeGroupNames, threeGroupIcons);
mExListViewAdapter = new LeftPanelExListViewAdapter(getContext(), mListItems);
mExpandableListView.setAdapter(mExListViewAdapter);
// 设置默认让所有组都展开
for (int i = 0; i < mListItems.size(); i++) {
mExpandableListView.expandGroup(i);
}
// 设置OnGroupClick时,不再展开或收缩组内的子项
mExpandableListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
// 表示GroupItem的单击事件已被处理
return true;
}
});
mExpandableListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
if (mOnSeletedListener == null) {
return false;
}
// 去掉上一次选中的项
mListItems.get(mGroupPosition).getGroups().get(mChildPosition).setSelected(false);
mGroupPosition = groupPosition;
mChildPosition = childPosition;
// 选中当前选择的项
mListItems.get(mGroupPosition).getGroups().get(mChildPosition).setSelected(true);
mExListViewAdapter.notifyDataSetChanged();
mOnSeletedListener.seletedChildView(groupPosition, childPosition);
return true;
}
});
}
/**
* 添加数据到指定的组
* @param groupId 组ID
* @param names 子项的名字数组
* @param icons 子项的图标数组
*/
private void addGroup(int groupId, String[] names, int[] icons) {
LeftPanelListItem listItem = new LeftPanelListItem();
listItem.setId(groupId);
listItem.setName(mGroupNames[groupId]);
// 组没有操作指示图标
// listItem.setDrawableId(drawableId);
ArrayList<LeftPanelListItem> firstGroup = new ArrayList<LeftPanelListItem>();
for (int i = 0; i < names.length; i++) {
LeftPanelListItem firstGroupItem = new LeftPanelListItem();
firstGroupItem.setId(i);
firstGroupItem.setName(names[i]);
firstGroupItem.setDrawableId(icons[i]);
// 默认选中第一组中的第一项
if (groupId == 0 && i== 0) {
firstGroupItem.setSelected(true);
}
// 可以无限延伸
// firstGroupItem.setGroups(null);
firstGroup.add(firstGroupItem);
}
listItem.setGroups(firstGroup);
mListItems.add(listItem);
}
/**
* 设置选中的Item事件监听器
* @param seletedListener
*/
public void setOnSeletedListener(onSeletedListener seletedListener) {
mOnSeletedListener = seletedListener;
}
/**
* 选中的Item事件监听器
* @author android_ls
*/
public interface onSeletedListener {
/**
* 当前选中的Item事件处理器
* @param groupPosition 所属组Id
* @param childPosition 在所属组内的位置
*/
public abstract void seletedChildView(int groupPosition, int childPosition);
}
/**
* 获取用户的基本信息
* @param accessToken
*/
public void getUserInfo(){
String accessToken = mAuthTokenManager.getAccessToken();
LogUtil.e(TAG, "accessToken = " + accessToken);
// 获取用户信息所需的参数
Map<String, String> parameter = new HashMap<String, String>();
parameter.put("v", "1.0"); // API的版本号,固定值为1.0
parameter.put("access_token", accessToken); // OAuth2.0验证授权后获得的token。
parameter.put("format", "JSON"); // 返回值的格式。请指定为JSON或者XML,推荐使用JSON,缺省值为XML
parameter.put("call_id", "1.0"); // 请求队列号
parameter.put("method", "users.getInfo"); // 你要访问那个接口,我们肯定调用用获取用户的信息的接口咯,该接口支持批量获取。
AsyncBaseRequest asyncHttpsPost = new AsyncHttpsPost(Constant.API_SERVER_URL, parameter, new ParseCallback() {
@Override
public Object parse(String json) throws JSONException {
LogUtil.i(TAG, "json = " + json);
Gson gson = new Gson();
java.lang.reflect.Type type = new TypeToken<LinkedList<UserBasicInfo>>() {}.getType();
LinkedList<UserBasicInfo> userList = gson.fromJson(json, type);
return userList.get(0);
}
}, new ResultCallback() {
@Override
public void onSuccess(Object obj) {
final UserBasicInfo user = (UserBasicInfo) obj;
LogUtil.i(TAG, "url = " + user.getHeadurl());
mHandler.post(new Runnable() {
@Override
public void run() {
// 设置当前用户的姓名或昵称
// tvNickname.setText(user.getName());
// 这里为了不透露本人真实姓名,就设置成固定值了
tvNickname.setText("android_ls");
String headUrl = user.getHeadurl();
LogUtil.i(TAG, "headUrl = " + user.getHeadurl());
// 用户图像的大小48x48,单位为dip,转换为px
int widthPx = DensityUtil.dip2px(mActivity, 48);
// 要一张圆角高质量的图片
ImageInfo imgInfo = new ImageInfo(ivUserIcon, headUrl, widthPx, widthPx, true, false);
mImageLoader.displayImage(imgInfo);
// 点击用户图像事件处理
ivUserIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(mActivity,PersonalHomepageActivity.class);
intent.putExtra("actor_id", user.getUid());
intent.putExtra("flage", 1); // 这里的标识值随便写了,呵呵
mActivity.startActivity(intent);
}
});
}
});
}
@Override
public void onFail(int errorCode) {
// TODO Auto-generated method stub
}
});
mDefaultThreadPool.execute(asyncHttpsPost);
mAsyncRequests.add(asyncHttpsPost);
// 请求失败返回的JSON
/* {
"request_args":
[
{"value":"1.0", "key":"v"},
{"value":"JSON","key":"format"},
{"value":"1.0","key":"call_id"},
{"value":"195789|6.017ad1db58c652f0fa5e9f32588a170e.2592000.1367838000-461345584","key":"access_token"}
],
"error_code":3,
"error_msg":"请求未知方法"
}*/
// 请求成功后返回的JSON
/*[
{
"uid":461345584,
"tinyurl":"http://hdn.xnimg.cn/photos/hdn521/20130319/1930/h_tiny_zggz_8829000002e6113e.jpg",
"vip":1,
"sex":1,
"name":"逐鹿。。。",
"star":1,
"headurl":"http://hdn.xnimg.cn/photos/hdn521/20130319/1930/h_head_jbdD_8829000002e6113e.jpg",
"zidou":0
}
]*/
}
}
LeftPanelExListViewAdapter类源码:
package com.everyone.android.ui.leftpanel;
import java.util.List;
import android.content.Context;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.everyone.android.R;
import com.everyone.android.entity.LeftPanelListItem;
/**
* 功能描述:左侧面板ExpandableListView组件数据适配器
* @author android_ls
*
*/
public class LeftPanelExListViewAdapter extends BaseExpandableListAdapter {
private Context mContext;
private List<LeftPanelListItem> mListItems;
public LeftPanelExListViewAdapter(Context context, List<LeftPanelListItem> listItems) {
mContext = context;
mListItems = listItems;
}
public LeftPanelListItem getChild(int groupPosition, int childPosition) {
return mListItems.get(groupPosition).getGroups().get(childPosition);
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
if (convertView == null) {
convertView = getItemLayout(80, R.drawable.left_panel_item_selector, 18, Color.GRAY, 30);
viewHolder = new ViewHolder();
viewHolder.groupName = (TextView) convertView.findViewById(0);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
LeftPanelListItem listItem = getChild(groupPosition, childPosition);
viewHolder.groupName.setCompoundDrawablesWithIntrinsicBounds(listItem.getDrawableId(), 0, 0, 0);
viewHolder.groupName.setCompoundDrawablePadding(10);
viewHolder.groupName.setText(listItem.getName());
if(listItem.isSelected()){
convertView.setBackgroundResource(R.drawable.menu_item_bg_sel);
viewHolder.groupName.setSelected(true);
} else {
convertView.setBackgroundResource(R.drawable.left_panel_item_selector);
viewHolder.groupName.setSelected(false);
}
return convertView;
}
public int getChildrenCount(int groupPosition) {
return mListItems.get(groupPosition).getGroups().size();
}
public LeftPanelListItem getGroup(int groupPosition) {
return mListItems.get(groupPosition);
}
public int getGroupCount() {
return mListItems.size();
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
if (convertView == null) {
convertView = getItemLayout(60, R.drawable.v5_0_1_desktop_list_item, 15, Color.WHITE, 20);
viewHolder = new ViewHolder();
viewHolder.groupName = (TextView) convertView.findViewById(0);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.groupName.setText(getGroup(groupPosition).getName());
return convertView;
}
public boolean hasStableIds() {
return false;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
static class ViewHolder {
public TextView groupName;
}
/**
* 根据参数配置获取相应的Layout
* @param height Layout高度
* @param backgroundId Layout的背景图片ID
* @param textSize 字体大小
* @param txetColor 字体颜色
* @param padding 文字距离左边的大小(间距)
* @return LinearLayout
*/
private LinearLayout getItemLayout(int height, int backgroundId, int textSize, int txetColor, int padding) {
LinearLayout layout = new LinearLayout(mContext);
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, height);
layout.setBackgroundResource(backgroundId);
layout.setGravity(Gravity.CENTER_VERTICAL);
layout.setLayoutParams(lp);
TextView textView = new TextView(mContext);
textView.setId(0);
textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
textView.setTextColor(txetColor);
textView.setPadding(padding, 0, 0, 0);
layout.addView(textView);
return layout;
}
}
以聊天列表视图为例,代码如下:
package com.everyone.android.ui.chat;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.everyone.android.R;
import com.everyone.android.ui.EveryoneActivity;
import com.everyone.android.widget.TopMenuNavbar;
/**
* 功能描述:聊天列表视图
* @author android_ls
*/
public class ChatLayout extends FrameLayout implements OnClickListener {
/**
* LOG打印标签
*/
private static final String TAG = ChatLayout.class.getSimpleName();
private TopMenuNavbar topMenuNavbar;
/**
* 获取顶部左侧的menu组件
* @return
*/
public LinearLayout getMenuView() {
return topMenuNavbar.llShowMenu;
}
private EveryoneActivity mActivity;
public ChatLayout(EveryoneActivity activity) {
super(activity);
mActivity = activity;
setupViews();
}
public ChatLayout(Context context, AttributeSet attrs) {
super(context, attrs);
setupViews();
}
private void setupViews() {
final LayoutInflater mLayoutInflater = LayoutInflater.from(getContext());
LinearLayout freshNewsViewRoot = (LinearLayout) mLayoutInflater.inflate(R.layout.chat, null);
addView(freshNewsViewRoot);
topMenuNavbar = (TopMenuNavbar) freshNewsViewRoot.findViewById(R.id.rl_top_menu_navbar);
LinearLayout llDownOperation = topMenuNavbar.mLlRefresh;
ImageView ivOperation = (ImageView) llDownOperation.findViewById(R.id.iv_refresh);
ivOperation.setImageResource(R.drawable.v5_0_1_flipper_head_add_chat_friends);
topMenuNavbar.mLlDownList.setOnClickListener(this);
topMenuNavbar.mLlRefresh.setOnClickListener(this);
topMenuNavbar.ivRightLine.setVisibility(View.GONE);
topMenuNavbar.tvRightOperationName.setVisibility(View.GONE);
topMenuNavbar.tvTitle.setText("聊天");
topMenuNavbar.ivDownListIcon.setVisibility(View.GONE);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
EveryoneActivity类,目前的源码如下:
package com.everyone.android.ui;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import com.everyone.android.api.NetworkBaseActivity;
import com.everyone.android.ui.chat.ChatLayout;
import com.everyone.android.ui.find.SearchLayout;
import com.everyone.android.ui.freshnews.FreshNewsLayout;
import com.everyone.android.ui.friend.FriendLayout;
import com.everyone.android.ui.leftpanel.LeftPanelLayout;
import com.everyone.android.ui.leftpanel.LeftPanelLayout.onSeletedListener;
import com.everyone.android.ui.message.MessageLayout;
import com.everyone.android.widget.ScrollerContainer;
/**
* 功能描述:应用主界面
* @author android_ls
*
*/
public class EveryoneActivity extends NetworkBaseActivity implements View.OnClickListener, onSeletedListener {
/**
* LOG打印标签
*/
private static final String TAG = EveryoneActivity.class.getSimpleName();
/**
* 滚动(滑动)容器
*/
private ScrollerContainer mSlideContainer;
/**
* 左侧面板
*/
private LeftPanelLayout mLeftPanelLayout;
/**
* 新鲜事
*/
private FreshNewsLayout mFreshNewsLayout;
/**
* 消息
*/
private MessageLayout mMessageLayout;
/**
* 聊天
*/
private ChatLayout mChatLayout;
/**
* 好友
*/
private FriendLayout mFriendLayout;
/**
* 查找
*/
private SearchLayout mSearchLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected int getLayoutId() {
return 0;
}
@Override
protected void setupViews() {
mSlideContainer = new ScrollerContainer(mContext);
mLeftPanelLayout = new LeftPanelLayout(EveryoneActivity.this);
mLeftPanelLayout.setOnSeletedListener(this);
mFreshNewsLayout = new FreshNewsLayout(EveryoneActivity.this);
mMessageLayout = new MessageLayout(EveryoneActivity.this);
mChatLayout = new ChatLayout(EveryoneActivity.this);
mFriendLayout = new FriendLayout(EveryoneActivity.this);
mSearchLayout = new SearchLayout(EveryoneActivity.this);
mFreshNewsLayout.getMenuView().setOnClickListener(this);
mMessageLayout.getMenuView().setOnClickListener(this);
mChatLayout.getMenuView().setOnClickListener(this);
mFriendLayout.getMenuView().setOnClickListener(this);
mSearchLayout.getMenuView().setOnClickListener(this);
LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
mSlideContainer.addView(mLeftPanelLayout, 0, layoutParams);
mSlideContainer.addView(mFreshNewsLayout, 1, layoutParams);
setContentView(mSlideContainer);
}
@Override
protected void initialized() {
mLeftPanelLayout.getUserInfo();
mFreshNewsLayout.getFreshNews();
}
@Override
public void onClick(View v) {
mSlideContainer.show();
}
@Override
public void seletedChildView(int groupPosition, int childPosition) {
switch (groupPosition) {
case 0:
switch (childPosition) {
case 0:
mSlideContainer.switchView(mFreshNewsLayout);
break;
case 1:
mSlideContainer.switchView(mMessageLayout);
break;
case 2:
mSlideContainer.switchView(mChatLayout);
break;
case 3:
mSlideContainer.switchView(mFriendLayout);
// 加载好友列表数据
mFriendLayout.getFriends();
break;
case 4:
mSlideContainer.switchView(mSearchLayout);
break;
default:
break;
}
break;
case 1:
switch (childPosition) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
default:
break;
}
break;
case 2:
switch (childPosition) {
case 0:
break;
case 1:
break;
default:
break;
}
break;
default:
break;
}
}
// Android按返回键退出程序但不销毁,程序后台运行,同QQ退出处理方式
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
moveTaskToBack(false);
return true;
}
return super.onKeyDown(keyCode, event);
}
}