Android首页底部常用tab切换控件,借鉴了Adapter
和AdapterView
的写法,可动态增减tab
可配合 ExpandableLayout
,快速实现 下拉筛选
菜单。
-
TabGroup
: 继承自LinearLayoutCompat
,支持配置divider
,类似于RadioGroup
,它们的API
基本相同 -
TabView
: 类似于CompoundButton
,实现了checkable
-
ExpandableRelativeLayout
: 一个可expandable
的RelativeLayout
. -
TabContainer
: 继承自TabGroup
, 使用了Adapter
模式,对应getView
方法,可以动态增减TabView
。 -
ExpandableContainer
: 继承自ExpandableRelativeLayout
,使用了Adapter
模式,对应getDropView
方法。 -
DropDownMenu
: 包含了TabContainer
和ExpandableContainer
,用以实现下拉筛选菜单功能。
compile 'com.bobomee.android:navigator:1.6'
- xml
<com.bobomee.android.navigator.dropdown.TabContainer
android:id="@+id/tab_container1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="@android:color/white"
android:elevation="10dp"
/>
- code
mTabContainer1.setTabAdapter(new AdapterBase<String>(mTitles) {
@Override public View getView(int position, ViewGroup parent, String object) {
ItemTabView itemTabView = new ItemTabView(getApplicationContext());
itemTabView.setText(object);
itemTabView.setId(position);
return itemTabView;
}
});
mDropDownMenu.setTabAdapter(new AdapterDropBase<String>(mTitles) {
@Override public View getView(int position, ViewGroup parent, String object) {
return tabView;
}
@Override public View getDropView(int position, ViewGroup parent, String object) {
return dropDownView;
}
});
mDropDownMenu.addDropDownMenuCheckedListener(new DropDownMenuCheckedListener() {
@Override public void onCheckedChange(int position, boolean checked) {
Log.d("BoBoMEe", "onCheckedChange: pos : " + position + ", checked: " + checked);
// get cheaked data or set tabview
}
});
//set the init state
mDropDownMenu.setExpanded(0, true);
- 全部API用法Demo: DropDownMenu_Activity.java
Copyright 2016 BoBoMEe([email protected])
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.