当前位置:编程学习 > wap >>

android中的TabHost?

layout代码:
<TabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost" 
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout 
    android:id="@android:id/tabcontent"
android:layout_width="fill_parent" 
android:layout_height="fill_parent" />
    
<RelativeLayout 
    android:orientation="vertical"
android:layout_width="match_parent" 
android:layout_height="match_parent"

>
<TabWidget 
    android:id="@android:id/tabs"
    android:background="#000000"     
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:tabStripEnabled="false"
android:layout_alignParentBottom="true"
/>

</RelativeLayout>
</TabHost>
java代码:
    mTabHost = (TabHost) findViewById(R.id.tabhost);
    mTabHost.setup(this.getLocalActivityManager());   
   
    mTabHost.addTab(mTabHost.newTabSpec("tab_index")
    .setIndicator("首页",getResources().getDrawable(R.drawable.divder))
    .setContent(new Intent(this, IndexActivity.class)));
为什么只能显示“首页”文字,而不能显示图片? --------------------编程问答-------------------- 个人感觉如下:
现在的代码貌似不支持同时显示图片和文字一样,你去看系统的源代码,在TabHost.java中。
final boolean exclusive = iconView.getVisibility() == View.GONE;
   final boolean bindIcon = !exclusive || TextUtils.isEmpty(mLabel);
 if (bindIcon && mIcon != null) {
                iconView.setImageDrawable(mIcon);
                iconView.setVisibility(VISIBLE);
            }


这里有一个exclusive判断ImageView是否显示。再看对应的tab_indicator_holo.xml文件。
<ImageView
        android:id="@android:id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:visibility="gone" />

看到没有,这里是不显示图片的,也就是说,只有在文字为空的时候才显示图片。 
个人理解是android自己定义的布局吧。
如果你把AndroidManifest.xml中的代码去掉:
	    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

是可以显示的,应该是以前的代码支持双显示吧。------以上为个人想法。 --------------------编程问答-------------------- 我去掉了以下代码还是不能显示呢?
 <uses-sdk

        android:minSdkVersion="8"

        android:targetSdkVersion="15" /> --------------------编程问答--------------------
引用 2 楼 zhangxingpei2006 的回复:
我去掉了以下代码还是不能显示呢?
 <uses-sdk

        android:minSdkVersion="8"

        android:targetSdkVersion="15" />


1.添加跟去掉有没有什么差别?我的是可以显示的。
2.看看去掉文字图片是不是显示了?代码流程就是按照上面的走的。 --------------------编程问答-------------------- 亲,你这句是肿么回事......android:id="@+id/tabhost" ??
应该是android:id="@android:id/tabhost"吧.........
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,