繁体   English   中英

TabHost图标扩展到最大大小

[英]TabHost Icon expand to maximum size

我通过使用tabHost遇到了一些问题。我试图将5个24x24 png文件插入到TabHost中,如下所示,但图标已扩展到tabhost的最大大小。

这是我的代码:

tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.xxx);
tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.xxx);
tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.xxx);
tabHost.getTabWidget().getChildAt(3).setBackgroundResource(R.drawable.xxx);
tabHost.getTabWidget().getChildAt(4).setBackgroundResource(R.drawable.xxx);

我厌倦了这段代码,但无法得到我想要的。

tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = (int) (30 * this.getResources().getDisplayMetrics().density);

我得到的是: http : //i860.photobucket.com/albums/ab166/season04/Capture_zpsrwblmx7y.png

我想要的是: http : //i860.photobucket.com/albums/ab166/season04/Capture_1_zpsvwaeu7gu.png

请帮忙

我已经用此代码和xml解决了我的问题。 =)

 private void addTab(String labelId, int drawableId, Class<?> c, int renewActivity) { Intent intent = new Intent(this, c); TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); View tabIndicator = LayoutInflater.from(this).inflate(R.layout.z_tab_indicator, getTabWidget(), false); ImageView icon = (ImageView) tabIndicator.findViewById(R.id.Tab_icon); icon.setImageResource(drawableId); spec.setIndicator(tabIndicator); switch (renewActivity) { case 0: spec.setContent(intent); break; case 1: spec.setContent(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); break; default: } tabHost.addTab(spec); } 

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="0dip" android:layout_height="45dip" android:layout_weight="1" android:orientation="vertical" android:padding="5dp"> <ImageView android:id="@+id/Tab_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#ffffff" android:layout_centerHorizontal="true" /> </RelativeLayout> 

如果有人有和我一样的问题。 =)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM