?
快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

亞虎官網登錄:實戰Android仿人人客戶端之應用主界面之左側面板UI實現

?

一、效果圖比較

各人官方的主界面截圖:

我仿的主界面之左側面板(仿,不必然要一樣,自己感覺看著不愜意的可以隨意率性改,呵呵)截圖:

二、編碼詳細實現

1、Layout結構文件(left_panel.xml)

xml version="1.0" encoding="utf-8"?>

LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"

android:layout_height="fill_parent"android:orientation="vertical" >

LinearLayout

android:layout_width="fill_parent"android:layout_height="wrap_content"

android:background="@drawable/left_panel_top_bg"android:gravity="center_vertical"

android:orientation="horizontal"android:padding="7dip" >

ImageView

android:id="@+id/iv_user_icon"android:layout_width="48dip"

android:layout_height="48dip"android:scaleType="centerCrop"

android:src="@drawable/v5_0_1_widget_default_head" />

TextViewandroid:id="@+id/tv_nickname"

android:layout_width="wrap_content"android:layout_height="wrap_content"

android:layout_marginLeft="10dip"android:text="逐鹿。。。"

android:textColor="#FFFFF0"android:textSize="17sp" />

LinearLayout>

ExpandableListViewandroid:id="@+id/elv_list_view"

android:layout_width="fill_parent"android:layout_height="wrap_content"

android:layout_weight="1.0"android:cacheColorHint="#FFFFFF"

android:childIndicator="@null"android:divider="@drawable/v5_0_1_flipper_head_popup_menu_black_divider"

android:dividerHeight="1px"android:fadingEdge="none"

android:footerDividersEnabled="false"android:groupIndicator="@null"

android:headerDividersEnabled="false"android:listSelector="#00000000"

android:scrollbars="none" />

LinearLayout>

2、初始化組件,構建數據

初始化組件

ivUserIcon = (ImageView) findViewById(R.id.iv_user_icon);

tvNickname = (TextView) findViewById(R.id.tv_nickname);mExpandableListView = (ExpandableListView) findViewById(R.id.elv_list_view);

構建分組數據

Resources resources = this.getResources();

mGroupNames = resources.getStringArray(R.array.left_panel_group_names);

String[] firstGr亞虎官網登錄oupNames = 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);

3、自定類承襲BaseExpandableListAdapter,實現左側面板ExpandableListView組件的數據適配器

package com.everyone.android.adapter;

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 mListItems;

public LeftPanelExListViewAdapter(Context context, List 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 == n亞虎官網登錄ull) {

convertView = getItemLayout(80, R.drawable.left_panel_item_selector, 18, Color.GRAY, 30);

viewHolder = new ViewHolder();viewHolder.groupN亞虎官網登錄ame = (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());

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;

}

}

4、給ExpandableListView設置數據適配器,并默認讓所有組都展開

mExListViewAdapter = new LeftPanelExListViewAdapter(this, mListItems);

mExpandableListView.setAdapter(mExListViewAdapter);

// 設置默認讓所有組都展開for (int i = 0; i

mExpandableListView.expandGroup(i);}

四、完備代碼

strings.xml文件

xml version="1.0" encoding="utf-8"?>

resources>string name="app_name">CopyEveryonestring>

string-array name="left_panel_group_names">

item>常用item>item>更多item>

item>操作item>string-array>

string-array name="left_panel_first_group_names">item>新鮮事item>

item>消息item>item>談天item>

item>石友item>item>找人item>

string-array>string-array name="left_panel_second_group_names">

item>相近item>item>公共主頁item>

item>熱門分享item>item>利用與游戲item>

string-array>string-array name="left_panel_group_three_names">

item>選項item>item>注銷登錄item>

string-array>

resources>

左側面板的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 ArrayList 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 ArrayList getGroups() {return groups;

}

public void setGroups(ArrayList groups) {this.groups = groups;

}

}

仿各人主界面之左側面板(LeftPanelActivity類)源碼:

package com.everyone.android.ui;

import java.util.ArrayList;

import java.util.List;

import android.content.res.Resources;import android.os.Bundle;

import android.widget.ExpandableListView;import android.widget.ImageView;

import android.widget.TextView;

import com.everyone.android.AppBaseActivity;import com.everyone.android.R;

import com.everyone.android.adapter.LeftPanelExListViewAdapter;import com.everyone.android.entity.LeftPanelListItem;

/奸淫 功能描述:仿各人主界面之左側面板

* @author android_ls*

*/ public class LeftPanelActivity extends AppBaseActivity {

/**

* 用戶圖標顯示組件*/

private ImageView ivUserIcon;

/奸淫 用戶名稱顯示組件

*/private TextView tvNickname;

/**

* 可展開的ListView組件*/

private ExpandableListView mExpandableListView;

/奸淫 ExpandableListView組件的數據適配器

*/private LeftPanelExListViewAdapter mExListViewAdapter;

/**

* ExpandableListView組件的數據源*/

private List mListItems = new ArrayList();

/奸淫 分組名數組

*/private String[] mGroupNames;

@Override

public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);

}

@Override

protected void setupView() {ivUserIcon = (ImageView) findViewById(R.id.iv_user_icon);

tvNickname = (TextView) findViewById(R.id.tv_nickname);mExpandableListView = (ExpandableListView) findViewById(R.id.elv_list_view);

}

@Override

protected int getLayoutId() {return R.layout.left_panel;

}

@Overrideprotected void initializedData() {

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_selecto亞虎官網登錄r,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(this, mListItems);mExpandableListView.setAdapter(mExListViewAdapter);

// 設置默認讓所有組都展開

for (int i = 0; imEx亞虎官網登錄pandableListView.expandGroup(i);

}

}

/奸淫 添加數據到指定的組

* @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 firstGroup = new ArrayList();

for (int i = 0; iLeftPanelListItem firstGroupItem = new LeftPanelListItem();

firstGroupItem.setId(i);firstGroupItem.setName(names[i]);

firstGroupItem.setDrawableId(icons[i]);

// 可以無限延伸// firstGroupItem.setGroups(null);

firstGroup.add(firstGroupItem);}

listItem.setGroups(firstGroup);

mListItems.add(listItem);}

}

轉自:http://blog.csdn.net/android_ls/article/details/8749188

免責聲明:以上內容源自網絡,版權歸原作者所有,如有侵犯您的原創版權請告知,我們將盡快刪除相關內容。

您可能還會對下面的文章感興趣:

河北十一选五开奖的 甘肃十一选五基本走势图 百度 福建22选5体彩论坛 江西快3二不同号是指 股票涨跌幅什么意思 手机看片在线 福建快三时时彩网 重庆百变王牌100期走势图 梦幻美女麻将 3d开机号试机号查 老11选5 分析软件 淑女派对 成人a片电影在线观看 云南十一选五开奖结果一定牛下载 陕西麻将胡牌规则 十分十一选五最新开奖结果 广西快乐10分走势