編輯:關於Android編程
源碼DEMO 等待審核中.......
-------------------------------------------------------------------------------------------------------------------------------------
1-原理,利用ANDROID原生控件ExpandableListview嵌套<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+Mi3Ktc/WVE9Qus1UV0+1xMrKxeTG9zwvcD4KPHA+LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLVRvcEV4cGFuZGFibGVMaXN0QWRhcHRlci5qYXZhLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tPC9wPgo8cD4vKio8YnI+CiAqIDIwMTMtMTEtMjIgyc/O5zk6Mzk6MTEgQ3JlYXRlZCBCeSBuaWV4aWFvcWlhbmc8YnI+CiAqLzxicj4KPGJyPgo8YnI+CnBhY2thZ2UgY29tLnhpYW9xaWFuZy50ZXN0Ozxicj4KPGJyPgo8YnI+CmltcG9ydCBqYXZhLnV0aWwuTGlzdDs8YnI+CmltcG9ydCBqYXZhLnV0aWwuTWFwOzxicj4KPGJyPgo8YnI+CmltcG9ydCBhbmRyb2lkLmNvbnRlbnQuQ29udGV4dDs8YnI+CmltcG9ydCBhbmRyb2lkLnZpZXcuR3Jhdml0eTs8YnI+CmltcG9ydCBhbmRyb2lkLnZpZXcuVmlldzs8YnI+CmltcG9ydCBhbmRyb2lkLnZpZXcuVmlld0dyb3VwOzxicj4KaW1wb3J0IGFuZHJvaWQud2lkZ2V0LkFic0xpc3RWaWV3Ozxicj4KaW1wb3J0IGFuZHJvaWQud2lkZ2V0LkFic0xpc3RWaWV3LkxheW91dFBhcmFtczs8YnI+CmltcG9ydCBhbmRyb2lkLndpZGdldC5CYXNlRXhwYW5kYWJsZUxpc3RBZGFwdGVyOzxicj4KaW1wb3J0IGFuZHJvaWQud2lkZ2V0LkV4cGFuZGFibGVMaXN0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BhbnlEYXRhcyA9IGFsbENvbnRhY3RzLmdldChjb21wYW55TmFtZSk7PGJyPgpyZXR1cm4gY29tcGFueURhdGFzOzxicj4KfTxicj4KPGJyPgo8YnI+CkBPdmVycmlkZTxicj4KcHVibGljIE9iamVjdCBnZXRDaGlsZChpbnQgZ3JvdXBQb3NpdGlvbiwgaW50IGNoaWxkUG9zaXRpb24pIHs8YnI+Ci8vILe1u9jEs7j2uavLvrXExLO49rK/w8W1xMr9vt08YnI+CkBTdXBwcmVzc1dhcm5pbmdzKA=="unchecked")
Map
String departmentName = (String) companyDatas.keySet().toArray()[childPosition];
// 返回一個返回一個list數據
return companyDatas.get(departmentName);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition * 100;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return groupPosition * 100 + childPosition * 10;
}
@Override
public boolean hasStableIds() {
return false;
}
public ExpandableListView getExpandableListView(Map
AbsListView.LayoutParams explvLP = new AbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, contact_row_height * companyDatas.size());
final ExpandableListView childExpandableListView = new ExpandableListView(context);
childExpandableListView.setLayoutParams(explvLP);
// 設置綁定
childExpandableListView.setPadding(contact_row_height, 0, 0, 0);
final TwoExpandableListAdapter twoExpandableListAdapter = new TwoExpandableListAdapter(contact_row_height, context, companyDatas, itemClickCallback);
childExpandableListView.setAdapter(twoExpandableListAdapter);
// 收
childExpandableListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
int currentDepartmentcount = twoExpandableListAdapter.getChildrenCount(groupPosition);
AbsListView.LayoutParams lp = (LayoutParams) childExpandableListView.getLayoutParams();
lp.height = lp.height - currentDepartmentcount * contact_row_height;
childExpandableListView.setLayoutParams(lp);
}
});
// 展
childExpandableListView.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
int currentDepartmentcount = twoExpandableListAdapter.getChildrenCount(groupPosition);
AbsListView.LayoutParams lp = (LayoutParams) childExpandableListView.getLayoutParams();
lp.height = lp.height + currentDepartmentcount * contact_row_height;
childExpandableListView.setLayoutParams(lp);
}
});
return childExpandableListView;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
TextView textView = new TextView(context);
textView.setLayoutParams(textviewLP);
textView.setPadding(contact_row_height, 0, 0, 0);
textView.setGravity(Gravity.CENTER_VERTICAL);
textView.setText((String) allContacts.keySet().toArray()[groupPosition]);
return textView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
String companyName = (String) allContacts.keySet().toArray()[groupPosition];
Map
ExpandableListView treeView = getExpandableListView(companyDatas);
return treeView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
}
-------------------------------------------------------------TwoExpandableListAdapter.java------------------------------------------------------------------------
/**
* 2013-11-22 上午11:03:06 Created By niexiaoqiang
*/
package com.xiaoqiang.test;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
/**
* TODO Add Class Description
*/
public class TwoExpandableListAdapter extends BaseExpandableListAdapter {
private Map
private Context context;
private ItemClickCallback callback;
private int contact_row_height;
public TwoExpandableListAdapter(int contact_row_height, Context context, Map
this.contact_row_height = contact_row_height;
this.context = context;
this.departmentContacts = departmentContacts;
this.callback = callback;
}
@Override
public int getGroupCount() {
// 得到公司下部門總數
return departmentContacts.size();
}
@Override
public int getChildrenCount(int groupPosition) {
// 得到某部門下,員工總數
return departmentContacts.get(departmentContacts.keySet().toArray()[groupPosition]).size();
}
@Override
public Object getGroup(int groupPosition) {
// 得到某部門下,員工的數據
return departmentContacts.get(departmentContacts.keySet().toArray()[groupPosition]);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return departmentContacts.get(departmentContacts.keySet().toArray()[groupPosition]).get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
// 部門*10
return groupPosition * 10;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// 部門*10+員工*1
return groupPosition * 10 + childPosition * 1;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
TextView textView = getTextView(0);
textView.setText((String) departmentContacts.keySet().toArray()[groupPosition]);
return textView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
TextView textView = getTextView(contact_row_height);
final ContactBean contactBean = departmentContacts.get(departmentContacts.keySet().toArray()[groupPosition]).get(childPosition);
textView.setText(contactBean.getName());
textView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (null != callback) {
callback.onClick(contactBean);
}
}
});
return textView;
}
/**
* 得到一個TextView
*
* @param paddingleft
* @return
*/
public TextView getTextView(int paddingleft) {
AbsListView.LayoutParams textviewLP = new AbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, contact_row_height);;
TextView textView = new TextView(context);
textView.setBackgroundResource(R.drawable.contact_selector);
textView.setLayoutParams(textviewLP);
textView.setPadding(contact_row_height, 0, 0, 0);
textView.setGravity(Gravity.CENTER_VERTICAL);
return textView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
public interface ItemClickCallback {
void onClick(ContactBean contactBean);
}
}
RxJava的簡單使用基本上也了解了,其實還有一個比較好玩的就是java8才有的lambda了。lambda在android studio下的環境搭建下載java8下面就
背景先看效果圖:(以公司附近的國貿為中心點)上面是地圖,下面是地理位置列表,有的只有地理位置列表(QQ動態的位置),這是個很常見的功能。它有個專門的叫法:POI周邊搜索。
前言 最近有個項目有關於播放音樂時候,關於歌詞有以下幾個功能: 1、實現歌詞同步滾動的功能,即歌曲播放到哪句歌詞,就高亮地顯示出正在播放的這個歌詞; 2、實現
Android:interpolatorInterpolator 被用來修飾動畫效果,定義動畫的變化率,可以使存在的動畫效果accelerated(加速),deceler