Android简单实现屏幕下方Tab菜单的方法

 更新时间:2016年08月18日 10:38:04   作者:与时俱进  
这篇文章主要介绍了Android简单实现屏幕下方Tab菜单的方法,简单分析了Android实现tab菜单所涉及的界面布局及功能相关操作技巧,需要的朋友可以参考下

本文实例讲述了Android简单实现屏幕下方Tab菜单的方法。分享给大家供大家参考,具体如下:

看到很多热门的Android程序(如:新浪微博、腾讯微博、京东商城、淘宝、当当等等)使用选项卡风格作为程序界面的主框架结构,而Android的选项卡控件默认是按钮在上方的。我在网上看到有多种实现方法,这里提供一种个人觉得比较简单的。由于我对Android开发所知甚少,方法的优劣目前不好评价,欢迎各位提供更好的思路。

主要原理:设置 TabWidget 控件的 android:layout_alignParentBottom="true" 实现。

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<TabHost android:id="@+id/tabhost" xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <RelativeLayout android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <TabWidget android:id="@android:id/tabs"
      android:layout_width="fill_parent" android:layout_height="wrap_content"
      android:layout_alignParentBottom="true" />
    <FrameLayout android:id="@android:id/tabcontent"
      android:layout_width="fill_parent" android:layout_height="fill_parent">
      <LinearLayout android:id="@+id/tab1"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        androidrientation="vertical">
        <TextView android:id="@+id/view1" android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:text="@string/textView_1" />
      </LinearLayout>
      <LinearLayout android:id="@+id/tab2"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        androidrientation="vertical">
        <TextView android:id="@+id/view2" android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:text="@string/textView_2" />
      </LinearLayout>
      <LinearLayout android:id="@+id/tab3"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        androidrientation="vertical">
        <TextView android:id="@+id/view3" android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:text="@string/textView_3" />
      </LinearLayout>
      <LinearLayout android:id="@+id/tab4"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        androidrientation="vertical">
        <TextView android:id="@+id/view4" android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:text="@string/textView_4" />
      </LinearLayout>
    </FrameLayout>
  </RelativeLayout>
</TabHost>

zhnews.java:

package net.zhnews.android;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
public class zhnews extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    setTitle("珠海新闻网Android客户端");
    TabHost tabs = (TabHost) findViewById(R.id.tabhost);
    tabs.setup();
    TabHost.TabSpec spec = tabs.newTabSpec("tab1");
    spec.setContent(R.id.tab1);
    spec.setIndicator("新闻");
    tabs.addTab(spec);
    spec = tabs.newTabSpec("tab2");
    spec.setContent(R.id.tab2);
    spec.setIndicator("搜联社");
    tabs.addTab(spec);
    spec = tabs.newTabSpec("tab3");
    spec.setContent(R.id.tab3);
    spec.setIndicator("影像");
    tabs.addTab(spec);
    spec = tabs.newTabSpec("tab4");
    spec.setContent(R.id.tab4);
    spec.setIndicator("设置");
    tabs.addTab(spec);
    tabs.setCurrentTab(0);
  }
}

更多关于Android相关内容感兴趣的读者可查看本站专题:《Android多媒体操作技巧汇总(音频,视频,录音等)》、《Android开发入门与进阶教程》、《Android视图View技巧总结》、《Android编程之activity操作技巧总结》、《Android操作SQLite数据库技巧总结》、《Android操作json格式数据技巧总结》、《Android数据库操作技巧总结》、《Android文件操作技巧汇总》、《Android编程开发之SD卡操作方法汇总》、《Android资源操作技巧汇总》及《Android控件用法总结

希望本文所述对大家Android程序设计有所帮助。

相关文章

  • Android如何给按钮添加点击音效

    Android如何给按钮添加点击音效

    这篇文章主要为大家详细介绍了Android如何给按钮添加点击音效,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-03-03
  • Android实现左侧滑动菜单

    Android实现左侧滑动菜单

    这篇文章主要为大家详细介绍了Android实现左侧滑动菜单,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-02-02
  • Android转场动画深入分析探究

    Android转场动画深入分析探究

    对于一个动画而言,它是由多个分镜头组成的,而转场就是分镜之间衔接方式。转场的主要目的,就是为了让镜头与镜头之间过渡的更加自然,让动画更加连贯,例如两个页面切换之间的衔接动画
    2022-10-10
  • Kotlin实现多函数接口的简化调用

    Kotlin实现多函数接口的简化调用

    这篇文章主要为大家详细介绍了Kotlin实现多函数接口的简化调用,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-06-06
  • Android实现评论栏随Recyclerview滑动左右移动

    Android实现评论栏随Recyclerview滑动左右移动

    这篇文章主要介绍了Android实现评论栏随Recyclerview滑动左右移动效果,仿约会吧应用详情页实现,感兴趣的小伙伴们可以参考一下
    2016-05-05
  • Android 监听手机GPS打开状态实现代码

    Android 监听手机GPS打开状态实现代码

    这篇文章主要介绍了Android 监听手机GPS打开状态实现代码的相关资料,需要的朋友可以参考下
    2017-05-05
  • Android端部署DeepSeek的详细教程

    Android端部署DeepSeek的详细教程

    DeepSeek最近几个月很火热,很多产品以及企业都在接入DeepSeek,比如微信搜索接入,可以搜索公众号信息并总结,这个对于查一些资料还挺好用,毕竟手机才是用户用的最多的,既然谈到了手机,那么DeepSeek能否部署于手机之上呢,本文给大家介绍了android端部署的DeepSeek方法
    2025-03-03
  • Android中使用ShareSDK集成分享功能的实例代码

    Android中使用ShareSDK集成分享功能的实例代码

    下面小编就为大家分享一篇Android中使用ShareSDK集成分享功能的实例代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-01-01
  • Android利用Intent启动和关闭Activity

    Android利用Intent启动和关闭Activity

    这篇文章主要为大家详细介绍了Android利用Intent启动和关闭Activity的相关操作,感兴趣的小伙伴们可以参考一下
    2016-06-06
  • Android 自定义SeekBar 实现分段显示不同背景颜色的示例代码

    Android 自定义SeekBar 实现分段显示不同背景颜色的示例代码

    这篇文章主要介绍了Android 自定义SeekBar 实现分段显示不同背景颜色,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-06-06

最新评论