最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android帶數(shù)字或紅點(diǎn)的底部導(dǎo)航攔和聯(lián)網(wǎng)等待加載動(dòng)畫示例

 更新時(shí)間:2017年03月02日 14:11:53   作者:HRobbie  
這篇文章主要介紹了Android帶數(shù)字或紅點(diǎn)的底部導(dǎo)航攔和聯(lián)網(wǎng)等待加載動(dòng)畫示例,具有一定的參考價(jià)值,有興趣的同學(xué)可以了解一下。

Android帶數(shù)字或紅點(diǎn)的底部導(dǎo)航攔和聯(lián)網(wǎng)等待加載動(dòng)畫

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

一、Android帶紅點(diǎn)的底部導(dǎo)航攔

1.首先寫底部導(dǎo)航欄的界面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="首頁(yè)"
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="進(jìn)貨單"
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="會(huì)員"
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.修改底部導(dǎo)航欄的數(shù)字,在MainActivity中

 /**
 * -1:表示沒有新消息
 * -2:表示新消息用紅點(diǎn)的方式顯示
 * 0-99:直接顯示數(shù)字
 * >=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中的底部導(dǎo)航攔,所以,要在MainActivity中,寫一些公用的方法。

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

4.在fragment中修改底部導(dǎo)航攔,得到主頁(yè)面,調(diào)用主頁(yè)面的修改方法。

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

二、activity加載動(dòng)畫。

1.activity中的加載動(dòng)畫,要寫一個(gè)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的布局里,包含了一個(gè)loading_anim的布局,這就是加載布局。加載布局,里面氛圍三個(gè)線性布局,分別是:加載中布局,加載錯(cuò)誤布局,沒有數(shù)據(jù)布局,其中加載失敗布局,還需要點(diǎn)擊重新加載。內(nèi)容如下:

<?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="看的越多,推薦越準(zhǔn)"
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="加載失敗,點(diǎn)擊重試"
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,沒有您想要的數(shù)據(jù)"
android:textSize="15sp" />
</LinearLayout>
</FrameLayout>

2.Baseactivity的代碼太多,講一下主要的,重寫setContentView方法,把新布局放入id為fl_content的布局中,調(diào)用getWindow()。setContentView(rootView);剩下的就跟普通個(gè)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,當(dāng)需要加載成功是,調(diào)用loadSuccess()方放,加載失敗時(shí)調(diào)用loadError(),失敗后重新加載,需要調(diào)用reLoading()重新加載,并調(diào)用onRefresh()重新加載數(shù)據(jù)。如果沒有數(shù)據(jù)調(diào)用noData()

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

1.viewpager進(jìn)行布局加載時(shí),最好能夠預(yù)加載一個(gè)屏幕的數(shù)據(jù)。

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

2.在BaseFragment重寫setUserVisibleHint方法,當(dāng)fragment可見時(shí),才聯(lián)網(wǎng)加載數(shù)據(jù)。

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

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

3.fragment繼承BaseFragment需要在onViewCreated中調(diào)用一下聯(lián)網(wǎng)加載方法,因?yàn)椋瑂etUserVisibleHint執(zhí)行比較靠前,頁(yè)面還沒有添加到布局,就加載數(shù)據(jù),會(huì)造成填充數(shù)據(jù)失敗,需要當(dāng)頁(yè)面完全添加到布局中,再聯(lián)網(wǎng)請(qǐng)求。

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

下載地址:LoadingProject_jb51.rar

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

科尔| 广河县| 休宁县| 兴化市| 昌邑市| 湛江市| 子洲县| 个旧市| 深圳市| 台中县| 康定县| 神池县| 文山县| 革吉县| 达州市| 望城县| 巨野县| 黄冈市| 保康县| 衡南县| 永和县| 麻江县| 无锡市| 阳春市| 卢氏县| 勃利县| 安乡县| 扬中市| 通城县| 志丹县| 延庆县| 舞阳县| 湖口县| 勐海县| 岐山县| 五常市| 定远县| 高台县| 读书| 二连浩特市| 乐都县|