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



  • 相关阅读:
    C艹老师布置的思考题
    计蒜客练习题:网页跳转(java / C++仔细)
    计蒜客练习题:水果店(嵌套map)
    计蒜客练习题:蒜头君面试(map + max_element)
    小希的迷宫 HDU 1272(并查集)
    OpenJ_Bailian 1061
    Aizu 2224(并查集)
    Aizu 0189 (最短路)
    POJ 2377(最大生成树)
    OpenJ_Bailian 4118(dp)
  • 原文地址:https://www.cnblogs.com/shanzei/p/2419367.html
Copyright © 2011-2022 走看看