欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android帶數字或紅點的底部導航攔和聯網等待加載動畫示例

 更新時間:2017年03月02日 14:11:53   作者:HRobbie  
這篇文章主要介紹了Android帶數字或紅點的底部導航攔和聯網等待加載動畫示例,具有一定的參考價值,有興趣的同學可以了解一下。

Android帶數字或紅點的底部導航攔和聯網等待加載動畫

首先展示一下截圖效果,下載地址在文章最后

一、Android帶紅點的底部導航攔

1.首先寫底部導航欄的界面view_main_tab.xml.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:background="#27282c"
>

<RelativeLayout
android:id="@+id/rl_1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:layout_weight="1">

<RadioButton
android:id="@+id/rb_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:button="@null"
android:background="@null"
android:checked="true"
android:clickable="false"
android:drawablePadding="5dp"
android:drawableTop="@drawable/selector_tab_home"
android:gravity="center"
android:text="首頁"
android:textColor="@drawable/tab_text_selector"
android:textSize="10sp" />

<TextView
android:id="@+id/tv_1"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignRight="@id/rb_1"
android:layout_alignTop="@id/rb_1"
android:layout_marginTop="-6dp"
android:layout_marginRight="-6dp"
android:layout_gravity="right"
android:background="@drawable/msg_num_shape"
android:clickable="false"
android:gravity="center"
android:text="3"
android:textColor="@color/white_1"
android:textSize="10sp"
/>

</RelativeLayout>

<RelativeLayout
android:id="@+id/rl_2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:focusable="true">

<RadioButton
android:id="@+id/rb_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@null"
android:button="@null"
android:clickable="false"
android:drawablePadding="5dp"
android:drawableTop="@drawable/selector_tab_goods_divide"
android:gravity="center"
android:text="商品"
android:textColor="@drawable/tab_text_selector"
android:textSize="10sp" />

<TextView
android:id="@+id/tv_2"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignRight="@id/rb_2"
android:layout_alignTop="@id/rb_2"
android:layout_marginTop="-6dp"
android:layout_marginRight="-6dp"
android:layout_gravity="right"
android:background="@drawable/msg_num_shape"
android:clickable="false"
android:gravity="center"
android:text="3"
android:textColor="@color/white_1"
android:textSize="10sp"
/>
</RelativeLayout>

<RelativeLayout
android:id="@+id/rl_3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:layout_weight="1">

<RadioButton
android:id="@+id/rb_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@null"
android:button="@null"
android:clickable="false"
android:drawablePadding="5dp"
android:drawableTop="@drawable/selector_tab_stock_list"
android:gravity="center"
android:text="進貨單"
android:textColor="@drawable/tab_text_selector"
android:textSize="10sp" />

<TextView
android:id="@+id/tv_3"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignRight="@id/rb_3"
android:layout_alignTop="@id/rb_3"
android:layout_marginTop="-6dp"
android:layout_gravity="right"
android:background="@drawable/msg_num_shape"
android:clickable="false"
android:gravity="center"
android:text="3"
android:textColor="@color/white_1"
android:textSize="10sp"
/>

</RelativeLayout>


<RelativeLayout
android:id="@+id/rl_4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:layout_weight="1">

<RadioButton
android:id="@+id/rb_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@null"
android:button="@null"
android:clickable="false"
android:drawablePadding="5dp"
android:drawableTop="@drawable/selector_tab_member"
android:gravity="center"
android:text="會員"
android:textColor="@drawable/tab_text_selector"
android:textSize="10sp" />


<TextView
android:id="@+id/tv_4"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignRight="@id/rb_4"
android:layout_alignTop="@id/rb_4"
android:layout_marginTop="-6dp"
android:layout_marginRight="-6dp"
android:layout_gravity="right"
android:background="@drawable/msg_num_shape"
android:clickable="false"
android:gravity="center"
android:text="3"
android:textColor="@color/white_1"
android:textSize="10sp"
/>
</RelativeLayout>

</LinearLayout>

2.修改底部導航欄的數字,在MainActivity中

 /**
 * -1:表示沒有新消息
 * -2:表示新消息用紅點的方式顯示
 * 0-99:直接顯示數字
 * >=100:用99+顯示
 */
private void messageTips(int num, TextView tv) {
if(num==-1){
 tv.setVisibility(View.GONE);
}else if(num==-2){
tv.setVisibility(View.VISIBLE);
tv.setText("");
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) tv.getLayoutParams();
layoutParams.height= DensityUtil.dip2px(this,10);
layoutParams.width= DensityUtil.dip2px(this,10);
tv.setLayoutParams(layoutParams);
}else if(num>=0&&num<=99){
tv.setVisibility(View.VISIBLE);
tv.setText(num+"");
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) tv.getLayoutParams();
layoutParams.height= DensityUtil.dip2px(this,16);
layoutParams.width= DensityUtil.dip2px(this,16);
tv.setLayoutParams(layoutParams);
}else if(num>=100){
tv.setVisibility(View.VISIBLE);
tv.setText("99+");
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) tv.getLayoutParams();
layoutParams.height= DensityUtil.dip2px(this,16);
layoutParams.width= DensityUtil.dip2px(this,16);
tv.setTextSize(DensityUtil.sp2px(this,3));
tv.setLayoutParams(layoutParams);
}else{
tv.setVisibility(View.GONE);
}

}

3.需要在fragment中修改MainActivity中的底部導航攔,所以,要在MainActivity中,寫一些公用的方法。

 /**
 * 在oneFragment中更新,底部導航欄的數字
 * @param num
 */
public void updateOne(int num){
messageTips(num,tv_1);
}
/**
 * 在TwoFragment中更新,底部導航欄的數字
 * @param num
 */
public void updateTwo(int num){
messageTips(num,tv_2);
}
/**
 * 在ThreeFragment中更新,底部導航欄的數字
 * @param num
 */
public void updateThree(int num){
messageTips(num,tv_3);
}
/**
 * 在FourFragment中更新,底部導航欄的數字
 * @param num
 */
public void updateFour(int num){
messageTips(num,tv_4);
}

4.在fragment中修改底部導航攔,得到主頁面,調用主頁面的修改方法。

mActivity = (MainActivity) getActivity();
number++;
mActivity.updateTwo(number);

二、activity加載動畫。

1.activity中的加載動畫,要寫一個BaseActivity。布局如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_base"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.hrobbie.loadingproject.activity.BaseActivity">


<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:contentInsetStart="0.0dp"
android:background="@color/colorPrimary"
app:layout_scrollFlags="enterAlways|scroll"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
<FrameLayout
android:id="@+id/fl_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/loading_anim"/>
</FrameLayout>

</LinearLayout>

注意:id為fl_content的FrameLayout的布局里,包含了一個loading_anim的布局,這就是加載布局。加載布局,里面氛圍三個線性布局,分別是:加載中布局,加載錯誤布局,沒有數據布局,其中加載失敗布局,還需要點擊重新加載。內容如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!--加載中-->
<LinearLayout android:id="@+id/ll_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="90dp"
android:gravity="center"
android:orientation="vertical"
>

<ImageView
android:id="@+id/iv_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/loading_everyday" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="正在為您開啟干貨推薦.."
android:textColor="@color/colorTitle"
android:textSize="14sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:text="看的越多,推薦越準"
android:textColor="@color/colorSubtitle"
android:textSize="12sp"
android:visibility="visible" />

</LinearLayout>


<!--加載失敗-->
<LinearLayout
android:id="@+id/ll_error_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">

<ImageView
android:id="@+id/img_err"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/load_err" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="加載失敗,點擊重試"
android:textSize="15sp" />
</LinearLayout>
<!--加載失敗-->
<LinearLayout
android:id="@+id/ll_no_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">

<ImageView
android:id="@+id/img_no_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/load_err" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="sorry,沒有您想要的數據"
android:textSize="15sp" />
</LinearLayout>
</FrameLayout>

2.Baseactivity的代碼太多,講一下主要的,重寫setContentView方法,把新布局放入id為fl_content的布局中,調用getWindow()。setContentView(rootView);剩下的就跟普通個activity操作一樣了。

@Override
public void setContentView(@LayoutRes int layoutResID) {
 View rootView = LayoutInflater.from(this).inflate(R.layout.activity_base,null,false);
addView = LayoutInflater.from(this).inflate(layoutResID, null, false);


//content
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
addView.setLayoutParams(params);
fl_content = (FrameLayout) rootView.findViewById(R.id.fl_content);
fl_content.addView(addView);
getWindow().setContentView(rootView);

initView();
showLoading();
}

3.新的activity只需集成BaseActivity,當需要加載成功是,調用loadSuccess()方放,加載失敗時調用loadError(),失敗后重新加載,需要調用reLoading()重新加載,并調用onRefresh()重新加載數據。如果沒有數據調用noData()

三、fragment中加載動畫,把加載布局,放入fragment中,我暫時沒有好的辦法提出BaseFragment進行統(tǒng)一加載。有一些注意事項。

1.viewpager進行布局加載時,最好能夠預加載一個屏幕的數據。

 vp_main.setOffscreenPageLimit(3);//最好是一屏能顯示的fragment數-1。

2.在BaseFragment重寫setUserVisibleHint方法,當fragment可見時,才聯網加載數據。

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);

if (getUserVisibleHint()){
isVisible=true;
onVisible();
}else {
isVisible=false;
onInvisible();
}
}

3.fragment繼承BaseFragment需要在onViewCreated中調用一下聯網加載方法,因為,setUserVisibleHint執(zhí)行比較靠前,頁面還沒有添加到布局,就加載數據,會造成填充數據失敗,需要當頁面完全添加到布局中,再聯網請求。

 @Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mActivity= (MainActivity) getActivity();
showLoading();
lazyLoad();
}

下載地址:LoadingProject_jb51.rar

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • kotlin源碼結構層次詳解

    kotlin源碼結構層次詳解

    這篇文章主要為大家介紹了kotlin源碼結構層次詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • Android實現水波紋特效

    Android實現水波紋特效

    這篇文章主要為大家詳細介紹了Android實現水波紋特效,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • Android 使用版本控制工具時添加忽略文件的方式(詳解)

    Android 使用版本控制工具時添加忽略文件的方式(詳解)

    下面小編就為大家?guī)硪黄狝ndroid 使用版本控制工具時添加忽略文件的方式(詳解)。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-01-01
  • Android Studio項目中導入開源庫的方法

    Android Studio項目中導入開源庫的方法

    這篇文章主要介紹了Android Studio項目中導入開源庫的方法,即使用第三方庫、第三廣場框架的方法,需要的朋友可以參考下
    2015-06-06
  • Android給通知channel靜音的方法實例

    Android給通知channel靜音的方法實例

    這篇文章主要給大家介紹了關于Android如何給通知channel靜音的相關資料,文中通過實例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2022-02-02
  • Android程序開發(fā)通過HttpURLConnection上傳文件到服務器

    Android程序開發(fā)通過HttpURLConnection上傳文件到服務器

    這篇文章主要介紹了Android程序開發(fā)通過HttpURLConnection上傳文件到服務器的相關資料,需要的朋友可以參考下
    2016-01-01
  • Android仿微信5實現滑動導航條

    Android仿微信5實現滑動導航條

    這篇文章主要為大家詳細介紹了Android仿微信5實現滑動導航條,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Android 進度條使用詳解及示例代碼

    Android 進度條使用詳解及示例代碼

    本文主要介紹Android 進度條的知識,這里整理了相關資料及實現示例代碼,有需要的小伙伴可以參考下
    2016-09-09
  • Android實現音頻錄音與播放

    Android實現音頻錄音與播放

    這篇文章主要為大家詳細介紹了Android實現音頻錄音與播放,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Android 超詳細講解fitsSystemWindows屬性的使用

    Android 超詳細講解fitsSystemWindows屬性的使用

    fitsSystemWindows屬性可以讓view根據系統(tǒng)窗口來調整自己的布局;簡單點說就是我們在設置應用布局時是否考慮系統(tǒng)窗口布局,這里系統(tǒng)窗口包括系統(tǒng)狀態(tài)欄、導航欄、輸入法等,包括一些手機系統(tǒng)帶有的底部虛擬按鍵
    2022-03-03

最新評論