【Android 新浪微博】--底部Tab的实现
来源:互联网 发布:上海万达网络科技集团 编辑:程序博客网 时间:2024/05/21 09:13
【Android 新浪微博】--底部Tab的实现
国际惯例先上图:
tabhost布局文件,注意tabhost,tabcontent和tabs这三个id一定要正确
- <?xml version="1.0" encoding="utf-8"?>
- <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@android:id/tabhost"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
- <RelativeLayout android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <FrameLayout android:id="@android:id/tabcontent"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
- <TabWidget android:id="@android:id/tabs"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@drawable/selector"
- android:layout_alignParentBottom="true">
- </TabWidget>
- </RelativeLayout>
- </TabHost>
每一个tab项的布局文件,上面图片下面是文字,
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <ImageView android:id="@+id/tab_iv_icon"
- android:layout_width="match_parent"
- android:layout_height="28.0dip"
- android:scaleType="fitCenter"/>
- <TextView android:id="@+id/tab_tv_text"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textSize="12.0sp"
- android:textColor="#FFFFFF"
- android:ellipsize="marquee"
- android:gravity="center"
- android:singleLine="true"
- android:marqueeRepeatLimit="1"/>
- </LinearLayout>
最后是MainActivity继承自TabActivity
- public class MainActivity extends TabActivity {
- private TabHost tabHost;
- private static final String HOME = "主页";
- private static final String REFER = "提及";
- private static final String ABOUT = "关于";
- private static final String SEARCH = "搜索";
- private static final String MORE = "更多";
- //内容Intent
- private Intent homeIntent;
- private Intent referIntent;
- private Intent aboutIntent;
- private Intent searchIntent;
- private Intent moreIntent;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.tabhost);//设置TabHost使用的布局文件
- tabHost=this.getTabHost();
- tabHost.setFocusable(true);
- prepareIntent();
- setupIntent();
- }
- private void setupIntent(){
- tabHost.addTab(buildTabSpec(HOME,R.drawable.icon_1_n, homeIntent));
- tabHost.addTab(buildTabSpec(REFER,R.drawable.icon_2_n, referIntent));
- tabHost.addTab(buildTabSpec(ABOUT,R.drawable.icon_3_n, aboutIntent));
- tabHost.addTab(buildTabSpec(SEARCH,R.drawable.icon_4_n, searchIntent));
- tabHost.addTab(buildTabSpec(MORE,R.drawable.icon_5_n, moreIntent));
- }
- private TabSpec buildTabSpec(String tag, int icon, Intent intent) {
- View view = View.inflate(MainActivity.this, R.layout.tab, null);
- ((ImageView)view.findViewById(R.id.tab_iv_icon)).setImageResource(icon);
- ((TextView)view.findViewById(R.id.tab_tv_text)).setText(tag);
- return tabHost.newTabSpec(tag)
- .setIndicator(view)
- .setContent(intent);
- }
- private void prepareIntent() {
- homeIntent=new Intent(this, HomeActivity.class);
- referIntent=new Intent(this, ReferActivity.class);
- aboutIntent=new Intent(this, AboutActivity.class);
- searchIntent=new Intent(this,SearchActivity.class);
- moreIntent=new Intent(this, MoreActivity.class);
- }
- }
0 0
- 【Android 新浪微博】--底部Tab的实现
- 【Android 新浪微博】--底部Tab的实现
- Android 高仿新浪微博底部导航栏,实现双击首页Tab,页面的ListView滚动、刷新
- android实现界面底部的tab
- Android中两种实现底部Tab的方法
- android实现界面底部的tab
- android Tab实现(仿新浪微博)
- android 用Fragment实现如新浪微博一样的底部菜单的切换
- 新浪微博开发二(底部菜单栏的实现)
- Android实现底部菜单Tab
- Android 新浪微博底部TabHost
- 底部Tab的实现(tabhost)
- Android 位于底部的Tab
- Android自定义View之实现流行的新浪微博底部菜单:高仿“咸鱼APP”的底部菜单动画效果。
- Android开发教程:底部Tab的两种实现方式
- android galary 底部Tab的两种实现方式
- Android 底部菜单栏Tab功能的几种实现方式
- Android底部Tab页基于ViewPager的实现
- TreeMap和TreeSet
- 第一天博客
- POJ 1047 Round and Round We GO
- 基于GPU的CUDA
- 浏览器兼容之CSS Hack
- 【Android 新浪微博】--底部Tab的实现
- 异常处理
- android 系统广播
- C/C++ 位移与乘除法的换算
- 求助!itk读取保存图像问题!
- jquery 选择器(name,属性,元素)大全
- HTTP幂等性
- C# 队列(Queue)
- Ubuntu下搭建eclipse开发环境