如何更改标签的大小 [英] How to change size of tabs
本文介绍了如何更改标签的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
其实我已经创建了一个标签在我app.here有三个tabs..but的事情是,我不能够在tabsan管理风格morevere我想要的大小一个标签比其他大2我送我的$ C $立方米普莱舍检查。
XML code:
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_height =match_parent
机器人:layout_width =match_parent
机器人:方向=横向
>
<的LinearLayout
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:填充=5DP>
< TabWidget
机器人:ID =@机器人:ID /标签
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
/>
<的FrameLayout
机器人:ID =@机器人:ID / tabcontent
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:填充=5DP
/>
< / LinearLayout中>
Java的code:
的setContentView(R.layout.main);
资源RES = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec规范;
意向意图;
//创建一个Intent来启动一个活动的标签(重复使用)
意图=新的意图()setClass(这一点,ContactActivity.class)。
规格= tabHost.newTabSpec(联系人)。setIndicator(联系人,
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(意向);
tabHost.addTab(规范);
//执行相同的其他标签
意图=新的意图()setClass(这一点,CallActivity.class)。
规格= tabHost.newTabSpec(CALL)。setIndicator(呼叫,
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(意向);
tabHost.addTab(规范);
意图=新的意图()setClass(这一点,MyInfoActivity.class)。
规格= tabHost.newTabSpec(我的信息)。setIndicator(MyInfo的,
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(意向);
tabHost.addTab(规范);
tabHost.setCurrentTab(2);
解决方案
下面的code改变标签的尺寸
显示显示= getWindowManager()getDefaultDisplay()。
INT宽度= display.getWidth();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
TabHost mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec(tab_test1)
.setIndicator((),getResources()。getDrawable(R.drawable.mzl_05))
.setContent(新意图(这一点,NearBy.class)));
mTabHost.addTab(mTabHost.newTabSpec(tab_test2)
.setIndicator((),getResources()。getDrawable(R.drawable.mzl_08))
.setContent(新意图(这一点,SearchBy.class)));
mTabHost.setCurrentTab(0);
mTabHost.getTabWidget()。getChildAt(0).setLayoutParams(新
LinearLayout.LayoutParams((宽度/ 2)-2,50));
mTabHost.getTabWidget()。getChildAt(1).setLayoutParams(新
LinearLayout.LayoutParams((宽度/ 2)-2,50));
我希望这是帮助全给你。
Actually i have created a tab in my app.here there are three tabs..but thing is that i am not able to manage style in the tabsan morevere i want size of one tab larger than the others two i am sending my code u plese check it..
XML CODE:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
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>
Java Code:
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, ContactActivity.class);
spec = tabHost.newTabSpec("Contacts").setIndicator("Contacts",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, CallActivity.class);
spec = tabHost.newTabSpec("Call").setIndicator("Call",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MyInfoActivity.class);
spec = tabHost.newTabSpec("My Info").setIndicator("MyInfo",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
解决方案
Here the code for changing the size of tab
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
TabHost mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab_test1")
.setIndicator((""),getResources().getDrawable(R.drawable.mzl_05))
.setContent(new Intent(this, NearBy.class)));
mTabHost.addTab(mTabHost.newTabSpec("tab_test2")
.setIndicator((""),getResources().getDrawable(R.drawable.mzl_08))
.setContent(new Intent(this, SearchBy.class)));
mTabHost.setCurrentTab(0);
mTabHost.getTabWidget().getChildAt(0).setLayoutParams(new
LinearLayout.LayoutParams((width/2)-2,50));
mTabHost.getTabWidget().getChildAt(1).setLayoutParams(new
LinearLayout.LayoutParams((width/2)-2,50));
I hope it is help full to you.
这篇关于如何更改标签的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文