Android 中的tablehost的tab使用图片不能完全填充

Android 中的tablehost的tab使用图片不能完全填充,第1张

TabWidget tabWidget = tabHost.getTabWidget()

// 设置tabhost里字体大小,位置 、图片大小

for (int i = 0i <tabWidget.getChildCount()i++) {

//有文字设置文字

TextView textView = (TextView) tabWidget.getChildAt(i)

.findViewById(android.R.id.title)

RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textView

.getLayoutParams()

params.setMargins(10, 50, 10, 2)// 设置控件位置,数字自己调

textView.setLayoutParams(params)

textView.setTextSize(10)

//有图片设置图片

ImageView image = (ImageView) tabWidget.getChildAt(i).findViewById(

android.R.id.icon)

tabWidget.getChildAt(i).setBackgroundResource(R.color.dibian)// 设置背景,你应该少了这个

RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) image

.getLayoutParams()

params1.setMargins(10, 10, 10, 10)//数字自己调

image.setLayoutParams(params1)

image.getLayoutParams().height = 40// 通过给它的属性赋值的方法可以解决问题

image.getLayoutParams().width = 55//数字自己调

}

tabHost.addTab(tabHost.newTabSpec("abcd").setIndicator(myview)

.setContent(R.id.adfaf))

其中 setIndicator 就是你设置的view 这个view就可以包含你的背景图片


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11517016.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存