Android仿微博首頁Tab加號彈窗功能
本文實(shí)例為大家分享了Android微博首頁Tab加號彈窗展示的具體代碼,供大家參考,具體內(nèi)容如下




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就是通過這些名字來查找對應(yīng)的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);
}
/**
* 導(dǎo)航按鈕被點(diǎn)擊時(shí),具體發(fā)生的變化
*/
@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:// 關(guān)閉按鈕
closePanelView();
break;
}
}
@Override
public boolean onTouch(final View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// 手指按下,按鈕執(zhí)行放大動畫
v.startAnimation(mButtonScaleLargeAnimation);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
// 手指移開,按鈕執(zhí)行縮小動畫
v.startAnimation(mButtonScaleSmallAnimation);
v.postDelayed(new Runnable() {
@Override
public void run() {
// 縮小動畫執(zhí)行完畢后,將按鈕的動畫清除。這里的150毫秒是縮小動畫的執(zhí)行時(shí)間。
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);
}
// 關(guān)閉面板視圖
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個按鈕的退出動畫執(zhí)行完畢后,將面板隱藏
mPanelView.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
}
XML 代碼
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<FrameLayout
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<RadioGroup
android:id="@+id/main_tabs"
style="@style/tab_bar" >
<RadioButton
android:id="@+id/radio_button0"
style="@style/tab_bar_item"
android:checked="true"
android:drawableTop="@drawable/icon_home"
android:text="首頁" />
<RadioButton
android:id="@+id/radio_button1"
style="@style/tab_bar_item"
android:drawableTop="@drawable/icon_meassage"
android:text="消息" />
<RelativeLayout
android:id="@+id/radio_button2"
android:layout_height="38dp"
android:layout_width="40dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center"
android:background="@drawable/tabbar_compose_bg_add_selector"
>
<ImageView
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:src="@drawable/tabbar_compose_icon_add_selector"/>
</RelativeLayout>
<!--android:drawableTop="@drawable/icon_selfinfo"-->
<!--android:text="好友"-->
<RadioButton
android:id="@+id/radio_button3"
style="@style/tab_bar_item"
android:drawableTop="@drawable/icon_square"
android:text="廣場" />
<RadioButton
android:id="@+id/radio_button4"
style="@style/tab_bar_item"
android:drawableTop="@drawable/icon_more"
android:text="更多" />
</RadioGroup>
</LinearLayout>
<include layout="@layout/view_add"/>
</FrameLayout>
自己剛剛需要做一個微博首頁的加號動態(tài)的效果的界面,于是在網(wǎng)上找相關(guān)資源,但找到的都是獨(dú)立的一個加號的顯示效果,沒有一個完整的tab中的效果,于是就整合了一個,分享給大家!
源碼下載:高仿微博首頁tab加號效果
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android屏幕鎖屏彈窗的正確姿勢DEMO詳解
- Android仿支付寶支付從底部彈窗效果
- Android如何實(shí)現(xiàn)鎖屏狀態(tài)下彈窗
- Android監(jiān)聽輸入法彈窗和關(guān)閉的實(shí)現(xiàn)方法
- Android實(shí)現(xiàn)氣泡布局/彈窗效果 氣泡尖角方向及偏移量可控
- Android仿支付寶微信支付密碼界面彈窗封裝dialog
- Android UI設(shè)計(jì)之AlertDialog彈窗控件
- Android自定義帶增長動畫和點(diǎn)擊彈窗提示效果的柱狀圖DEMO
- Android程序開發(fā)仿新版QQ鎖屏下彈窗功能
- Android控件PopupWindow模仿ios底部彈窗
相關(guān)文章
Android 屏幕切換監(jiān)聽的實(shí)例代碼
我試著在屏幕切換時(shí),使View顯示在不同的位置,在網(wǎng)上搜索了一些資料,自己做了一段時(shí)間,終于完成了功能,今天小編給大家分享android 屏幕切換監(jiān)聽的實(shí)例代碼,需要的的朋友參考下吧2017-01-01
android startActivityForResult的使用方法介紹
android startActivityForResult的使用方法介紹,需要的朋友可以參考一下2013-05-05
通過Android trace文件分析死鎖ANR實(shí)例過程
遇到ANR(Application Not Responding)是比較常見的問題,產(chǎn)生ANR的原因有很多,比如CPU使用過高、事件沒有得到及時(shí)的響應(yīng)、死鎖等,下面將通過一次因?yàn)樗梨i導(dǎo)致的ANR問題,來說明如何通過trace文件分析ANR問題2013-06-06
flutter實(shí)現(xiàn)底部導(dǎo)航欄切換
這篇文章主要為大家詳細(xì)介紹了flutter實(shí)現(xiàn)底部導(dǎo)航欄切換,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07
Android中的sqlite查詢數(shù)據(jù)時(shí)去掉重復(fù)值的方法實(shí)例
今天小編就為大家分享一篇關(guān)于Android中的sqlite查詢數(shù)據(jù)時(shí)去掉重復(fù)值的方法實(shí)例,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-01-01
利用libmp3lame實(shí)現(xiàn)在Android上錄音MP3文件示例
本篇文章主要介紹了利用Lame庫實(shí)現(xiàn)在Android上錄音MP3文件示例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-03-03
Android仿蘋果關(guān)機(jī)界面實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了Android仿蘋果關(guān)機(jī)界面的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09
Android 處理OnItemClickListener時(shí)關(guān)于焦點(diǎn)顏色的設(shè)置問題
這篇文章主要介紹了Android 處理OnItemClickListener時(shí)關(guān)于焦點(diǎn)顏色的設(shè)置問題的相關(guān)資料,需要的朋友可以參考下2017-02-02
Android利用MediaRecorder實(shí)現(xiàn)錄音功能
這篇文章主要為大家詳細(xì)介紹了Android利用MediaRecorder實(shí)現(xiàn)錄音功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03

