版权声明:随便转载 共同进步! https://blog.csdn.net/MacaoPark/article/details/79706303
需求就是实现一个类似腾讯WiFi的底部导航
先上一个效果图
实现思路
(1)UI布局我采用的 RelativeLayout 加FrameLayout 还有RadioGroup来实现的
(2)中间那个WiFi按钮是一个属性动画效果(缩放与渐变)
XML代码
<?xml version="1.0" encoding="utf-8"?>
<com.zhy.autolayout.AutoRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.zhy.autolayout.AutoFrameLayout
android:id="@+id/layFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/rg_home"
android:background="#288" />
<com.zhy.autolayout.AutoFrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<RadioGroup
android:id="@+id/rg_home"
android:layout_width="match_parent"
android:layout_height="110px"
android:paddingBottom="5px"
android:layout_gravity="bottom"
android:background="@android:color/white"
android:orientation="horizontal"
android:paddingTop="5px">
<RadioButton
android:id="@+id/rb_regulator"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:checked="true"
android:drawableTop="@drawable/radiobutton_home_select"
android:gravity="center"
android:text="管理"
android:textColor="@drawable/main_radiobutton_text"
android:textSize="12sp" />
<RadioButton
android:id="@+id/rb_wifi"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:button="@null"
android:drawableTop="@drawable/radiobutton_wifi_select"
android:gravity="center"
android:paddingTop="6dp" />
<RadioButton
android:id="@+id/rb_find"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/radiobutton_home_select"
android:gravity="center"
android:text="发现"
android:textColor="@drawable/main_radiobutton_text"
android:textSize="12sp" />
</RadioGroup>
<com.zhy.autolayout.AutoLinearLayout
android:id="@+id/ll_btn"
android:layout_width="225px"
android:layout_height="67px"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="30dp"
android:background="@drawable/wifi_bg"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:id="@+id/tv_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="12px"
android:text="安全连接"
android:textColor="#FFF"
android:textSize="14.5sp" />
</com.zhy.autolayout.AutoLinearLayout>
</com.zhy.autolayout.AutoFrameLayout>
</com.zhy.autolayout.AutoRelativeLayout>
*适配我采用的是鸿洋大神的autolayout,所以布局是AutoRelativeLayout
按钮动画代码
【1】开启动画
private void StartFlash() {
AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1.0f);
alphaAnimation.setDuration(440);
ScaleAnimation scaleAnimation = new ScaleAnimation(
0, 1,
0, 1,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(440);
AnimationSet animationSet = new AnimationSet(false);
animationSet.addAnimation(alphaAnimation);
animationSet.addAnimation(scaleAnimation);
ll_btn.startAnimation(animationSet);
xy =true;
}
【2】关闭动画
private void StopFlash() {
AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0);
alphaAnimation.setDuration(440);
ScaleAnimation scaleAnimation = new ScaleAnimation(
1, 0,
1, 0,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(440);
AnimationSet animationSet = new AnimationSet(false);
animationSet.addAnimation(alphaAnimation);
animationSet.addAnimation(scaleAnimation);
ll_btn.startAnimation(animationSet);
animationSet.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
rbWifi.setVisibility(View.VISIBLE);
ll_btn.setVisibility(View.GONE);
xy =false;
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
.