-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
544 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
app/src/main/java/com/chaychan/powerfulviewlibrary/activity/BottomBarLayoutDemoActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.chaychan.powerfulviewlibrary.activity; | ||
|
||
import android.os.Bundle; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentActivity; | ||
import android.support.v4.app.FragmentManager; | ||
import android.support.v4.app.FragmentStatePagerAdapter; | ||
import android.support.v4.view.ViewPager; | ||
|
||
import com.chaychan.powerfulviewlibrary.R; | ||
import com.chaychan.powerfulviewlibrary.fragment.TabFragment; | ||
import com.chaychan.viewlib.bottombarlayout.BottomBarLayout; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import butterknife.Bind; | ||
import butterknife.ButterKnife; | ||
|
||
public class BottomBarLayoutDemoActivity extends FragmentActivity { | ||
|
||
@Bind(R.id.vp_content) | ||
ViewPager vpContent; | ||
@Bind(R.id.bbl) | ||
BottomBarLayout bbl; | ||
|
||
private List<TabFragment> mFragmentList = new ArrayList<>(); | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_bottom_bar_layout_demo); | ||
ButterKnife.bind(this); | ||
|
||
initData(); | ||
initListener(); | ||
} | ||
|
||
private void initData() { | ||
|
||
TabFragment homeFragment = new TabFragment(); | ||
Bundle bundle1 = new Bundle(); | ||
bundle1.putString(TabFragment.CONTENT,"首页"); | ||
homeFragment.setArguments(bundle1); | ||
mFragmentList.add(homeFragment); | ||
|
||
TabFragment videoFragment = new TabFragment(); | ||
Bundle bundle2 = new Bundle(); | ||
bundle2.putString(TabFragment.CONTENT,"视频"); | ||
videoFragment.setArguments(bundle2); | ||
mFragmentList.add(videoFragment); | ||
|
||
TabFragment microFragment = new TabFragment(); | ||
Bundle bundle3 = new Bundle(); | ||
bundle3.putString(TabFragment.CONTENT,"微头条"); | ||
microFragment.setArguments(bundle3); | ||
mFragmentList.add(microFragment); | ||
|
||
TabFragment meFragment = new TabFragment(); | ||
Bundle bundle4 = new Bundle(); | ||
bundle4.putString(TabFragment.CONTENT,"我的"); | ||
meFragment.setArguments(bundle4); | ||
mFragmentList.add(meFragment); | ||
} | ||
|
||
private void initListener() { | ||
vpContent.setAdapter(new MyAdapter(getSupportFragmentManager())); | ||
bbl.setmViewPager(vpContent); | ||
} | ||
|
||
class MyAdapter extends FragmentStatePagerAdapter{ | ||
|
||
public MyAdapter(FragmentManager fm) { | ||
super(fm); | ||
} | ||
|
||
@Override | ||
public Fragment getItem(int position) { | ||
return mFragmentList.get(position); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return mFragmentList.size(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/chaychan/powerfulviewlibrary/fragment/TabFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.chaychan.powerfulviewlibrary.fragment; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.view.Gravity; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
/** | ||
* @author ChayChan | ||
* @date 2017/6/23 11:22 | ||
*/ | ||
public class TabFragment extends Fragment { | ||
|
||
public static final String CONTENT = "content"; | ||
private TextView mTextView; | ||
|
||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle bundle) { | ||
mTextView = new TextView(getActivity()); | ||
mTextView.setGravity(Gravity.CENTER); | ||
String content = getArguments().getString(CONTENT); | ||
mTextView.setText(content); | ||
return mTextView; | ||
} | ||
|
||
|
||
} |
82 changes: 82 additions & 0 deletions
82
app/src/main/res/layout/activity_bottom_bar_layout_demo.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
> | ||
|
||
<android.support.v4.view.ViewPager | ||
android:id="@+id/vp_content" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_weight="1" | ||
></android.support.v4.view.ViewPager> | ||
|
||
<com.chaychan.viewlib.bottombarlayout.BottomBarLayout | ||
android:id="@+id/bbl" | ||
android:layout_width="match_parent" | ||
android:layout_height="56dp" | ||
android:orientation="horizontal" | ||
android:gravity="center" | ||
android:layout_gravity="center" | ||
android:background="@color/tab_gb" | ||
> | ||
|
||
<com.chaychan.viewlib.bottombarlayout.BottomBarItem | ||
android:layout_width="0dp" | ||
android:layout_weight="1" | ||
android:layout_height="match_parent" | ||
app:iconNormal="@mipmap/tab_home_normal" | ||
app:iconSelected="@mipmap/tab_home_selected" | ||
app:itemText="首页" | ||
app:textColorNormal="@color/tab_normal_color" | ||
app:textColorSelected="@color/tab_selected_color" | ||
app:itemTextSize="10sp" | ||
app:itemMarginTop="0dp" | ||
/> | ||
|
||
<com.chaychan.viewlib.bottombarlayout.BottomBarItem | ||
android:layout_width="0dp" | ||
android:layout_weight="1" | ||
android:layout_height="match_parent" | ||
app:iconNormal="@mipmap/tab_video_normal" | ||
app:iconSelected="@mipmap/tab_video_selected" | ||
app:itemText="视频" | ||
app:textColorNormal="@color/tab_normal_color" | ||
app:textColorSelected="@color/tab_selected_color" | ||
app:itemTextSize="10sp" | ||
app:itemMarginTop="0dp" | ||
/> | ||
|
||
|
||
<com.chaychan.viewlib.bottombarlayout.BottomBarItem | ||
android:layout_width="0dp" | ||
android:layout_weight="1" | ||
android:layout_height="match_parent" | ||
app:iconNormal="@mipmap/tab_micro_normal" | ||
app:iconSelected="@mipmap/tab_micro_selected" | ||
app:itemText="微头条" | ||
app:textColorNormal="@color/tab_normal_color" | ||
app:textColorSelected="@color/tab_selected_color" | ||
app:itemTextSize="10sp" | ||
app:itemMarginTop="0dp" | ||
/> | ||
|
||
<com.chaychan.viewlib.bottombarlayout.BottomBarItem | ||
android:layout_width="0dp" | ||
android:layout_weight="1" | ||
android:layout_height="match_parent" | ||
app:iconNormal="@mipmap/tab_me_normal" | ||
app:iconSelected="@mipmap/tab_me_selected" | ||
app:itemText="我的" | ||
app:textColorNormal="@color/tab_normal_color" | ||
app:textColorSelected="@color/tab_selected_color" | ||
app:itemTextSize="10sp" | ||
app:itemMarginTop="0dp" | ||
/> | ||
|
||
</com.chaychan.viewlib.bottombarlayout.BottomBarLayout> | ||
|
||
</LinearLayout> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
viewlib/src/main/java/com/chaychan/viewlib/bottombarlayout/BottomBarItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.chaychan.viewlib.bottombarlayout; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.support.annotation.Nullable; | ||
import android.util.AttributeSet; | ||
import android.view.Gravity; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
|
||
import com.chaychan.viewlib.R; | ||
import com.chaychan.viewlib.utils.UIUtils; | ||
|
||
|
||
/** | ||
* @author ChayChan | ||
* @description: 底部tab条目 | ||
* @date 2017/6/23 9:14 | ||
*/ | ||
|
||
public class BottomBarItem extends LinearLayout { | ||
|
||
private Context mContext; | ||
private int mIconNormalResourceId;//普通状态图标的资源id | ||
private int mIconSelectedResourceId;//选中状态图标的资源id | ||
private String mText;//文本 | ||
private int mTextSize = 12;//文字大小 默认为12sp | ||
private int mTextColorNormal = 0xFF999999; //描述文本的默认显示颜色 | ||
private int mTextColorSelected = 0xFF46C01B; //述文本的默认选中显示颜色 | ||
private int mMarginTop = 5;//文字和图标的距离,默认5dp | ||
private TextView mTextView; | ||
private ImageView mImageView; | ||
|
||
public BottomBarItem(Context context) { | ||
this(context, null); | ||
} | ||
|
||
public BottomBarItem(Context context, @Nullable AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public BottomBarItem(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
|
||
mContext = context; | ||
|
||
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.BottomBarItem); | ||
|
||
mIconNormalResourceId = ta.getResourceId(R.styleable.BottomBarItem_iconNormal, -1); | ||
mIconSelectedResourceId = ta.getResourceId(R.styleable.BottomBarItem_iconSelected, -1); | ||
|
||
mText = ta.getString(R.styleable.BottomBarItem_itemText); | ||
mTextSize = ta.getDimensionPixelSize(R.styleable.BottomBarItem_itemTextSize, UIUtils.sp2px(mContext,mTextSize)); | ||
|
||
mTextColorNormal = ta.getColor(R.styleable.BottomBarItem_textColorNormal, mTextColorNormal); | ||
mTextColorSelected = ta.getColor(R.styleable.BottomBarItem_textColorSelected, mTextColorSelected); | ||
|
||
mMarginTop = ta.getDimensionPixelSize(R.styleable.BottomBarItem_itemMarginTop, UIUtils.dip2Px(mContext, mMarginTop)); | ||
ta.recycle(); | ||
|
||
checkValues(); | ||
init(); | ||
} | ||
|
||
/** | ||
* 检查传入的值是否完善 | ||
*/ | ||
private void checkValues() { | ||
if (mIconNormalResourceId == -1) { | ||
throw new IllegalStateException("您还没有设置默认状态下的图标,请指定iconNormal的图标"); | ||
} | ||
|
||
if (mIconSelectedResourceId == -1) { | ||
throw new IllegalStateException("您还没有设置选中状态下的图标,请指定iconSelected的图标"); | ||
} | ||
} | ||
|
||
private void init() { | ||
setOrientation(VERTICAL); | ||
setGravity(Gravity.CENTER); | ||
|
||
View view = View.inflate(mContext, R.layout.item_bottom_bar, null); | ||
mImageView = (ImageView) view.findViewById(R.id.iv_icon); | ||
mTextView = (TextView) view.findViewById(R.id.tv_text); | ||
|
||
mImageView.setImageResource(mIconNormalResourceId); | ||
mTextView.getPaint().setTextSize(mTextSize); | ||
mTextView.setText(mText); | ||
mTextView.setTextColor(mTextColorNormal); | ||
|
||
LinearLayout.LayoutParams layoutParams = (LayoutParams) mTextView.getLayoutParams(); | ||
layoutParams.topMargin = mMarginTop; | ||
mTextView.setLayoutParams(layoutParams); | ||
|
||
addView(view); | ||
} | ||
|
||
private ImageView createImageView() { | ||
mImageView = new ImageView(mContext); | ||
mImageView.setImageResource(mIconNormalResourceId); | ||
return mImageView; | ||
} | ||
|
||
private TextView creatTextView() { | ||
mTextView = new TextView(mContext); | ||
|
||
mTextView.setGravity(Gravity.CENTER); | ||
return mTextView; | ||
} | ||
|
||
public void setStatus(boolean isSelected){ | ||
mImageView.setImageResource(isSelected?mIconSelectedResourceId:mIconNormalResourceId); | ||
mTextView.setTextColor(isSelected?mTextColorSelected:mTextColorNormal); | ||
} | ||
} |
Oops, something went wrong.