zoukankan      html  css  js  c++  java
  • 竖型tabHost

    导读:所以要想让TabSpec的头(spec的Indicator)竖直排列也就需要我们把TabWidget的排列方式设成Vertical的然后Tabwidget与TabSpec的content部分横着排列,而TabWidget继承自LinearLayout

     所以原本想在布局文件中直接加android:orientation="horizontal"可是悲剧的是失败了,究其原因是因为在源码中TabWidget在initTabWidget中又做了一次setOrientation(LinearLayout.HORIZONTAL);的初始化,所以最后决定重写Tabwidget部分。代码部分如下:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation
    ="vertical" android:layout_width="fill_parent"

    android:layout_height
    ="fill_parent">

    <TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent"

    android:layout_height
    ="fill_parent">

    <LinearLayout android:orientation="horizontal"

    android:layout_width
    ="fill_parent" android:layout_height="fill_parent"

    android:padding
    ="5dp">

    <com.gw.android.VerticalTabWigdet android:id="@android:id/tabs"

    android:layout_width
    ="wrap_content" android:layout_height="wrap_content" />

    <FrameLayout android:id="@android:id/tabcontent"

    android:layout_width
    ="fill_parent" android:layout_height="fill_parent"

    android:padding
    ="5dp" />

    </LinearLayout>

    </TabHost>
    </LinearLayout>

     重写的TabWidget代码:

    public class VerticalTabWigdet extends TabWidget {
    &nbsp; &nbsp;Resources res;



    public VerticalTabWigdet(Context context, AttributeSet attrs) {

    super(context, attrs);

    // TODO Auto-generated constructor stub

    res=context.getResources();

    setOrientation(LinearLayout.VERTICAL);

    }


    @Override

    public void addView(View child) {

    // TODO Auto-generated method stub

    LinearLayout.LayoutParams lp = new LayoutParams(

    LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f);

    lp.setMargins(0, 0, 0, 0);

    child.setLayoutParams(lp);

    super.addView(child);

    child.setBackgroundDrawable(res.getDrawable(R.drawable.vertical_tab_selector));

    }

    }

    \" data-mce-src=

    转自:http://www.eoeandroid.com/qa/2011/1226/497.html



  • 相关阅读:
    mysql的备份与恢复(windows、Linux并拷贝至备机)
    eclipse导出可执行jar
    ORCLE中两张表对比更新合入(MERGE INTO)
    js中事件冒泡的问题
    Spring事务传播行为详解
    Java中的锁分类与使用
    用某浏览器全屏延时启动应用
    Springboot整合WebSocket的交互实例(点对点、点对面)
    Windows程序设计------字体不等宽引出的问题及其细节知识
    关于VS2013使用constexpr报错问题
  • 原文地址:https://www.cnblogs.com/shanzei/p/2419367.html
Copyright © 2011-2022 走看看