垂直对齐文本中心标签主机 [英] Align text center vertically in tab Host
本文介绍了垂直对齐文本中心标签主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要在标签主机vertcally设定在中央的文字。我试图重力中心,但仍然没有工作。
<?XML版本=1.0编码=UTF-8&GT?;
< TabHost的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@机器人:ID / tabhost
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT> <的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直> < TabWidget
机器人:ID =@机器人:ID /标签
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT/> <的FrameLayout
机器人:ID =@机器人:ID / tabcontent
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT/>
< / LinearLayout中>< / TabHost>
解决方案
请在编程:
TabHost tabHost =(TabHost)findViewById(R.id.tabHost);
tabHost.setup(); //设置您的标签 RelativeLayout.LayoutParams rllp =新RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
rllp.addRule(RelativeLayout.CENTER_IN_PARENT); 的for(int i = 0; I< tabHost.getTabWidget()getChildCount();我++){
tabHost.getTabWidget()getChildAt(ⅰ).findViewById(android.R.id.title).setLayoutParams(rllp)。
}
I want to set the text at center vertcally in tab host. I tried gravity to center but still not working.
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<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" />
</LinearLayout>
</TabHost>
解决方案
Do that programatically:
TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
tabHost.setup();
// setup your tabs
RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
rllp.addRule(RelativeLayout.CENTER_IN_PARENT);
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title).setLayoutParams(rllp);
}
这篇关于垂直对齐文本中心标签主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文