本文实例为大家分享了Android微博首页Tab加号弹窗展示的具体代码,供大家参考,具体内容如下
成都创新互联长期为1000+客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为铁门关企业提供专业的成都网站建设、成都做网站,铁门关网站改版等技术服务。拥有十余年丰富建站经验和众多成功案例,为您定制开发。
Activity部分的代码
package com.ting.tab; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.CompoundButton; import android.widget.RadioButton; import com.ting.ContentActivity0; import com.ting.ContentActivity1; import com.ting.ContentActivity2; import com.ting.ContentActivity3; import com.ting.ContentActivity4; import com.ting.R; public class TabActivityGroup extends AbstractActivityGroup implements View.OnClickListener, View.OnTouchListener { // 加载的Activity的名字,LocalActivityManager就是通过这些名字来查找对应的Activity的。 private static final String CONTENT_0 = "contentActivity0"; private static final String CONTENT_1 = "contentActivity1"; private static final String CONTENT_2 = "contentActivity2"; private static final String CONTENT_3 = "contentActivity3"; private static final String CONTENT_4 = "contentActivity4"; private View addButton; private View mPanelView; private View mCloseButton; private View mIdeaButton; private View mPhotoButton; private View mWeiboButton; private View mLbsButton; private View mReviewButton; private View mMoreButton; private Animation mButtonInAnimation; private Animation mButtonOutAnimation; private Animation mButtonScaleLargeAnimation; private Animation mButtonScaleSmallAnimation; private Animation mCloseRotateAnimation; @Override protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_tab); super.onCreate(savedInstanceState); initView(); initAnimation(); ((RadioButton) findViewById(R.id.radio_button0)).setChecked(true); setContainerView(CONTENT_0, ContentActivity0.class); } /** * 找到自定义id的加载Activity的View */ @Override protected ViewGroup getContainer() { return (ViewGroup) findViewById(R.id.container); } /** * 初始化按钮 */ @Override protected void initTabBarButtons() { initTabBarButton(R.id.radio_button0); initTabBarButton(R.id.radio_button1); // initTabBarButton(R.id.radio_button2); initTabBarButton(R.id.radio_button3); initTabBarButton(R.id.radio_button4); } /** * 导航按钮被点击时,具体发生的变化 */ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { switch (buttonView.getId()) { case R.id.radio_button0: setContainerView(CONTENT_0, ContentActivity0.class); break; case R.id.radio_button1: setContainerView(CONTENT_1, ContentActivity1.class); break; case R.id.radio_button2: // setContainerView(CONTENT_2, ContentActivity2.class); break; case R.id.radio_button3: setContainerView(CONTENT_3, ContentActivity3.class); break; case R.id.radio_button4: setContainerView(CONTENT_4, ContentActivity4.class); break; default: break; } } } //以下是仿微博加号控件添加代码 private void initView() { addButton = findViewById(R.id.radio_button2); mPanelView = findViewById(R.id.panel); mCloseButton = findViewById(R.id.close); mIdeaButton = findViewById(R.id.idea_btn); mPhotoButton = findViewById(R.id.photo_btn); mWeiboButton = findViewById(R.id.weibo_btn); mLbsButton = findViewById(R.id.lbs_btn); mReviewButton = findViewById(R.id.review_btn); mMoreButton = findViewById(R.id.more_btn); addButton.setOnClickListener(this); mCloseButton.setOnClickListener(this); mIdeaButton.setOnTouchListener(this); mPhotoButton.setOnTouchListener(this); mWeiboButton.setOnTouchListener(this); mLbsButton.setOnTouchListener(this); mReviewButton.setOnTouchListener(this); mMoreButton.setOnTouchListener(this); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.radio_button2:// 添加按钮 openPanelView(); break; case R.id.close:// 关闭按钮 closePanelView(); break; } } @Override public boolean onTouch(final View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // 手指按下,按钮执行放大动画 v.startAnimation(mButtonScaleLargeAnimation); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: // 手指移开,按钮执行缩小动画 v.startAnimation(mButtonScaleSmallAnimation); v.postDelayed(new Runnable() { @Override public void run() { // 缩小动画执行完毕后,将按钮的动画清除。这里的150毫秒是缩小动画的执行时间。 v.clearAnimation(); } }, 150); break; } return true; } // 打开面板视图 private void openPanelView() { mPanelView.setVisibility(View.VISIBLE); mIdeaButton.startAnimation(mButtonInAnimation); mPhotoButton.startAnimation(mButtonInAnimation); mWeiboButton.startAnimation(mButtonInAnimation); mLbsButton.startAnimation(mButtonInAnimation); mReviewButton.startAnimation(mButtonInAnimation); mMoreButton.startAnimation(mButtonInAnimation); mCloseButton.startAnimation(mCloseRotateAnimation); } // 关闭面板视图 private void closePanelView() { // 给6个按钮添加退出动画 mIdeaButton.startAnimation(mButtonOutAnimation); mPhotoButton.startAnimation(mButtonOutAnimation); mWeiboButton.startAnimation(mButtonOutAnimation); mLbsButton.startAnimation(mButtonOutAnimation); mReviewButton.startAnimation(mButtonOutAnimation); mMoreButton.startAnimation(mButtonOutAnimation); } // 初始化动画 private void initAnimation() { mButtonInAnimation = AnimationUtils.loadAnimation(this, R.anim.button_in); mButtonOutAnimation = AnimationUtils.loadAnimation(this, R.anim.button_out); mButtonScaleLargeAnimation = AnimationUtils.loadAnimation(this, R.anim.button_scale_to_large); mButtonScaleSmallAnimation = AnimationUtils.loadAnimation(this, R.anim.button_scale_to_small); mCloseRotateAnimation = AnimationUtils.loadAnimation(this, R.anim.close_rotate); mButtonOutAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { // 6个按钮的退出动画执行完毕后,将面板隐藏 mPanelView.setVisibility(View.GONE); } @Override public void onAnimationRepeat(Animation animation) { } }); } }
XML 代码
<?xml version="1.0" encoding="utf-8"?>
自己刚刚需要做一个微博首页的加号动态的效果的界面,于是在网上找相关资源,但找到的都是独立的一个加号的显示效果,没有一个完整的tab中的效果,于是就整合了一个,分享给大家!
源码下载:高仿微博首页tab加号效果
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。