我给TabWidget自定义了背景图片,为什么图片四周都有空,不能紧靠边缘?
如图:
第一个标签我没添加图片,第二个添加的是系统自带的图片,第三个是我自己做的图片,为什么第三个图片四周有空隙?

解决方案 »

  1.   

    这是为什么呀,怎么都搞不定了
    刚刚新建了一个测试用的工程,什么东西都没加,也是不行,图片大小:200*100
    下面是我的main.xml,谁能帮我看看有问题没,要怎么修改。
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout 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_marginTop="0dp" android:paddingTop="0dp" />
    <FrameLayout android:id="@android:id/tabcontent"
    android:layout_width="fill_parent" android:layout_height="wrap_content"/>
    </LinearLayout></TabHost> 
      

  2.   


    我按照楼主的方法也试了下,发现真有空白的地方,期待高手解决!
    不过这个需求应该不怎么重要吧,或者不用tabhost做,直接用三个button放上面,然后动态改变下面部分的布局应该可以吧!
      

  3.   

    android:layout_height="wrap_content"
    改成
    android:layout_height="fill_parent"
    试试
    毕竟你的图片宽高比是2:1的
      

  4.   

      <TabWidget android:id="@android:id/tabs"
                 android:layout_width="fill_parent" android:layout_height="wrap_content"/>这样就可以了吧,宽度填充父窗口,高度自适应。建议LZ把图片做成9.png再试试。系统会自动拉伸的。
      

  5.   

    是文件名为xxx.9.png吗?这样的话eclipse报错,在文件夹上有红叉
      

  6.   

    tabwidget可以自己实现现实的view而不用自带的那个,setIndicator有一个重载参数是View的
      

  7.   

    for (int i = 0; i < tabHost.getChildCount(); i++) { tabWidget.getChildAt(i).setBackgroundResource(R.drawable.bg_tab);
    }
    楼主 试试这样?
      

  8.   


    最后一问,什么叫把图片做成9.png,我把图片命名为XXX.9.png,eclipse文件夹红叉,运行报错,能不能再说两句
      

  9.   

    view.setBackgroundDrawable(),用这个方法就可以啦,android可以把图片拉伸
      

  10.   

    网上找下,9.png的图片做起来很简单的
      

  11.   

    lz 我今天也遇到这个问题了你的图像尺寸 不符合 TAB的比例
    按照320x480的分辨率
    一共4个TAB 那个每个 320/4 = 80高度你如果自适应的话, 那么如果 height:80  != 你的图像的 weight/height那么就会出现你所说的情况修改一下图像尺寸 应该就没问题了
      

  12.   

    你试试 aaa×aaa 的图片 就是正方形的图
      

  13.   

    图片加载的地方加个:android:scaleType="center"