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

高仿網(wǎng)易新聞頂部滑動(dòng)條效果實(shí)現(xiàn)代碼

 更新時(shí)間:2013年01月02日 16:15:51   作者:  
網(wǎng)易新聞的主界面頂部的滑動(dòng)條個(gè)人感覺(jué)還是比較漂亮的所以今天也模仿了下,網(wǎng)易頂部滑動(dòng)條的效果,由于初次模仿這種效果,可能有些地方還不夠完美,不過(guò)基本已經(jīng)實(shí)現(xiàn),希望大家能夠喜歡

這個(gè)是網(wǎng)易新聞的主界面,我們知道底部可以用tabhost實(shí)現(xiàn),這個(gè)很容易,我們?cè)谄渌浖幸矔?huì)經(jīng)常用到。
至于頂部的滑動(dòng)條,個(gè)人感覺(jué)還是比較漂亮的所以今天也模仿了下,網(wǎng)易頂部滑動(dòng)條的效果,由于初次模仿這種效果,可能有些地方還不夠完美,不過(guò)基本已經(jīng)實(shí)現(xiàn),希望大家能夠喜歡。
廢話不多說(shuō),下面上代碼:
首先是布局layout下的main.xml
復(fù)制代碼 代碼如下:

<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:background="#ffffff"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/layoutBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/big_button_up"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.0">
<TextView
android:id="@+id/tab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="新聞"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.0">
<TextView
android:id="@+id/tab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="體育"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.0">
<TextView
android:id="@+id/tab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="娛樂(lè)"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.0">
<TextView
android:id="@+id/tab4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="更多"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/page"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/layoutBar"
android:background="#ffffff"
android:orientation="vertical"
>
</LinearLayout>
</RelativeLayout>

下面是核心類(lèi),
復(fù)制代碼 代碼如下:

packagecn.com.karl.slider;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.Gravity;
importandroid.view.LayoutInflater;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.view.ViewGroup.LayoutParams;
importandroid.view.animation.TranslateAnimation;
importandroid.widget.LinearLayout;
importandroid.widget.RelativeLayout;
importandroid.widget.TextView;
publicclassSliderBarActivityextendsActivity{
/**Calledwhentheactivityisfirstcreated.*/
privateRelativeLayoutlayout;

privateRelativeLayoutlayout1;
privateRelativeLayoutlayout2;
privateRelativeLayoutlayout3;
privateRelativeLayoutlayout4;
privateTextViewtab1;
privateTextViewtab2;
privateTextViewtab3;
privateTextViewtab4;
privateTextViewfirst;
privateintcurrent=1;

privateLinearLayoutpage;

privatebooleanisAdd=false;
privateintselect_width;
privateintselect_height;
privateintfirstLeft;
privateintstartLeft;

@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
privatevoidinit(){
layout=(RelativeLayout)findViewById(R.id.root);

layout1=(RelativeLayout)findViewById(R.id.layout1);
layout2=(RelativeLayout)findViewById(R.id.layout2);
layout3=(RelativeLayout)findViewById(R.id.layout3);
layout4=(RelativeLayout)findViewById(R.id.layout4);

page=(LinearLayout)this.findViewById(R.id.page);

tab1=(TextView)findViewById(R.id.tab1);
tab1.setOnClickListener(onClickListener);
tab2=(TextView)findViewById(R.id.tab2);
tab2.setOnClickListener(onClickListener);
tab3=(TextView)findViewById(R.id.tab3);
tab3.setOnClickListener(onClickListener);
tab4=(TextView)findViewById(R.id.tab4);
tab4.setOnClickListener(onClickListener);



RelativeLayout.LayoutParamsrl=newRelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
rl.addRule(RelativeLayout.CENTER_IN_PARENT,RelativeLayout.TRUE);
first=newTextView(this);
first.setTag("first");
first.setGravity(Gravity.CENTER);
first.setBackgroundResource(R.drawable.slidebar);
first.setText(tab1.getText());
Viewview1=LayoutInflater.from(getApplicationContext()).inflate(R.layout.page1,null);
page.addView(view1);

switch(current){
case1:
layout1.addView(first,rl);
current=R.id.tab1;
break;
case2:
layout2.addView(first,rl);
current=R.id.tab2;
break;
case3:
layout3.addView(first,rl);
current=R.id.tab3;
break;
case4:
layout4.addView(first,rl);
current=R.id.tab4;
break;
default:
break;
}

}

privatevoidreplace(){
switch(current){
caseR.id.tab1:
changeTop(layout1);
break;
caseR.id.tab2:
changeTop(layout2);
break;
caseR.id.tab3:
changeTop(layout3);
break;
caseR.id.tab4:
changeTop(layout4);
break;
default:
break;
}
}
privatevoidchangeTop(RelativeLayoutrelativeLayout){
TextViewold=(TextView)relativeLayout.findViewWithTag("first");;
select_width=old.getWidth();
select_height=old.getHeight();

RelativeLayout.LayoutParamsrl=newRelativeLayout.LayoutParams(select_width,select_height);
rl.leftMargin=old.getLeft()+((RelativeLayout)old.getParent()).getLeft();
rl.topMargin=old.getTop()+((RelativeLayout)old.getParent()).getTop();

firstLeft=old.getLeft()+((RelativeLayout)old.getParent()).getLeft();

TextViewtv=newTextView(this);
tv.setTag("move");
tv.setBackgroundResource(R.drawable.slidebar);

layout.addView(tv,rl);
relativeLayout.removeView(old);
}

privateOnClickListeneronClickListener=newOnClickListener(){
publicvoidonClick(Viewv){
if(!isAdd){
replace();
isAdd=true;
}

TextViewtop_select=(TextView)layout.findViewWithTag("move");
top_select.setGravity(Gravity.CENTER);
top_select.setText(tab1.getText());
inttabLeft;
intendLeft=0;

booleanrun=false;
switch(v.getId()){
caseR.id.tab1:
if(current!=R.id.tab1){
page.removeAllViews();
tabLeft=((RelativeLayout)tab1.getParent()).getLeft()+tab1.getLeft()+tab1.getWidth()/2;
endLeft=tabLeft-select_width/2;
current=R.id.tab1;
top_select.setText(tab1.getText());
run=true;
Viewview1=LayoutInflater.from(getApplicationContext()).inflate(R.layout.page1,null);
page.addView(view1);
}
break;
caseR.id.tab2:
if(current!=R.id.tab2){
page.removeAllViews();
tabLeft=((RelativeLayout)tab2.getParent()).getLeft()+tab2.getLeft()+tab2.getWidth()/2;
endLeft=tabLeft-select_width/2;
current=R.id.tab2;
top_select.setText(tab2.getText());
run=true;
Viewview2=LayoutInflater.from(getApplicationContext()).inflate(R.layout.page2,null);
page.addView(view2);
}
break;
caseR.id.tab3:
if(current!=R.id.tab3){
page.removeAllViews();
tabLeft=((RelativeLayout)tab3.getParent()).getLeft()+tab3.getLeft()+tab3.getWidth()/2;
endLeft=tabLeft-select_width/2;
current=R.id.tab3;
top_select.setText(tab3.getText());
run=true;
Viewview3=LayoutInflater.from(getApplicationContext()).inflate(R.layout.page3,null);
page.addView(view3);
}
break;
caseR.id.tab4:
if(current!=R.id.tab4){
page.removeAllViews();
tabLeft=((RelativeLayout)tab4.getParent()).getLeft()+tab3.getLeft()+tab4.getWidth()/2;
endLeft=tabLeft-select_width/2;
current=R.id.tab4;
top_select.setText(tab4.getText());
run=true;
Viewview4=LayoutInflater.from(getApplicationContext()).inflate(R.layout.page4,null);
page.addView(view4);
}
break;
default:
break;
}

if(run){
TranslateAnimationanimation=newTranslateAnimation(startLeft,endLeft-firstLeft,0,0);
startLeft=endLeft-firstLeft;
animation.setDuration(100);
animation.setFillAfter(true);
top_select.bringToFront();
top_select.startAnimation(animation);

}

}
};
}

由于時(shí)間比較緊,我沒(méi)有做注釋,有時(shí)間再做注釋啊。
看一下效果是不是一樣??!

   

 
效果還請(qǐng)大家自行體驗(yàn)并改進(jìn),由于時(shí)間倉(cāng)促,代碼并未做注釋,希望大家能夠原諒

相關(guān)文章

  • 使用SignalR推送服務(wù)在Android的實(shí)現(xiàn) SignalA

    使用SignalR推送服務(wù)在Android的實(shí)現(xiàn) SignalA

    SignalA是老外寫(xiě)的用于實(shí)現(xiàn).net端推送消息至安卓端的實(shí)現(xiàn),支持版本為android 2.3或以上
    2014-07-07
  • Android網(wǎng)絡(luò)判斷知識(shí)小結(jié)

    Android網(wǎng)絡(luò)判斷知識(shí)小結(jié)

    本文通過(guò)兩段實(shí)例代碼分別給大家介紹Android中判斷當(dāng)前網(wǎng)絡(luò)是否可用和Android 關(guān)于判斷應(yīng)用是否有網(wǎng)絡(luò)的相關(guān)知識(shí),對(duì)android網(wǎng)絡(luò)判斷相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧
    2015-12-12
  • Android ActionBar制作時(shí)鐘實(shí)例解析

    Android ActionBar制作時(shí)鐘實(shí)例解析

    這篇文章主要為大家詳細(xì)介紹了Android ActionBar制作時(shí)鐘的實(shí)現(xiàn)代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-05-05
  • Android RetainFragment狀態(tài)保存的方法

    Android RetainFragment狀態(tài)保存的方法

    本篇文章主要介紹了Android RetainFragment狀態(tài)保存的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-02-02
  • Flutter以兩種方式實(shí)現(xiàn)App主題切換的代碼

    Flutter以兩種方式實(shí)現(xiàn)App主題切換的代碼

    這篇文章主要介紹了Flutter以兩種方式實(shí)現(xiàn)App主題切換的代碼,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-04-04
  • 詳解Retrofit2.0 公共參數(shù)(固定參數(shù))

    詳解Retrofit2.0 公共參數(shù)(固定參數(shù))

    這篇文章主要介紹了Retrofit2.0 公共參數(shù)(固定參數(shù)),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-04-04
  • Android Intent啟動(dòng)別的應(yīng)用實(shí)現(xiàn)方法

    Android Intent啟動(dòng)別的應(yīng)用實(shí)現(xiàn)方法

    我們知道Intent的應(yīng)用,可以啟動(dòng)別一個(gè)Activity,那么是否可以啟動(dòng)別外的一個(gè)應(yīng)用程序呢,答案是可以的
    2013-04-04
  • Flutter 給列表增加下拉刷新和上滑加載更多功能

    Flutter 給列表增加下拉刷新和上滑加載更多功能

    在實(shí)際的 App 中,下拉刷新和上滑加載更多是非常常見(jiàn)的交互形式。在 Flutter 中,有 flutter_easyrefresh開(kāi)源插件用于實(shí)現(xiàn)下拉刷新和上滑加載更多。本篇介紹了有狀態(tài)組件和 flutter_easyrefresh 的基本應(yīng)用,同時(shí)使用模擬的方式完成了異步數(shù)據(jù)加載。
    2021-05-05
  • android中okhttp實(shí)現(xiàn)斷點(diǎn)上傳示例

    android中okhttp實(shí)現(xiàn)斷點(diǎn)上傳示例

    本篇文章主要介紹了android中okhttp實(shí)現(xiàn)斷點(diǎn)上傳示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-02-02
  • Android okhttp使用的方法

    Android okhttp使用的方法

    本篇文章主要介紹了Android okhttp使用的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-02-02

最新評(píng)論

陆丰市| 闸北区| 灵宝市| 武冈市| 犍为县| 碌曲县| 探索| 河东区| 清镇市| 涿鹿县| 务川| 余干县| 菏泽市| 仙游县| 武隆县| 萝北县| 德州市| 陵水| 云浮市| 昂仁县| 沈丘县| 贞丰县| 偏关县| 铁岭县| 永德县| 林西县| 昌平区| 张家口市| 萝北县| 政和县| 山东省| 铜陵市| 德惠市| 延边| 肇源县| 长岭县| 巴彦淖尔市| 金堂县| 鹤峰县| 安庆市| 余庆县|