`
弄月吟风
  • 浏览: 197111 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Android超级简单的TabView实现

阅读更多

可能很多人都有想要实现一个导航栏,但是不知道改怎么弄,因为android自带的TabView是在顶部的,这里我们提供一个超级简单的实现方法,首先我们建立一个布局文件,我这里叫做buttonbar.xml,其次我们开始实现我们的代码<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
        <LinearLayout
        style="@android:style/ButtonBar"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:background="@drawable/buttonbar"
        android:gravity="center"
        android:orientation="horizontal" >
        <ImageButton
            android:id="@+id/shouye"
            android:scaleType="fitXY"
            android:layout_width="0dip" 
            android:layout_height="50dip"          
            android:layout_weight="1"
            android:background="#00000000"
             />
        <ImageButton
            android:id="@+id/fenlei"
            android:scaleType="fitXY"
            android:layout_width="0dip" 
            android:layout_height="50dip"  
            android:layout_weight="1"
            android:background="#00ffffff"
             />
        <ImageButton
            android:id="@+id/shoucang"
            android:scaleType="fitXY"
            android:layout_width="0dip" 
            android:layout_height="50dip"  
            android:layout_weight="1"
            android:background="#00ffffff"
             />
        <ImageButton
            android:id="@+id/gengduo"
            android:scaleType="fitXY"
            android:layout_width="0dip" 
            android:layout_height="50dip"  
            android:layout_weight="1"
            android:background="#00ffffff"
             />       
    </LinearLayout>
</LinearLayout>

 解释一下代码: style="@android:style/ButtonBar"设置布局格式为导航栏类型, android:background="@drawable/buttonbar"设置一张图片,

这张图片就是我们一个导航栏的截图,图上有几个按钮,我们就在布局里面放几个按钮,并且给按钮这定权值,这样就能使得按钮充满这

,个空间,然后就没有然后了、、你自己点击一下,看看效果就知道了、、、

当然我们也可以使用别的方法,不采用系统的效果,比如给每个按钮的背景设定一个布局文件,然后根据这个按钮是否点击来选择不同的背景颜色

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics