我刚开始编程的机器人。我使用一个标签为基础的布局在我的应用程序。我想提出一些填充周围的选项卡标签,以便它不是如此接近的图标。
在这里是怎样的标签贴在:
在main.java
规格= tabHost.newTabSpec(TAB1)。setIndicator(this.getString(R.string.tab1),res.getDrawable(R.drawable.ic_tab1))。setContent(意图);
和在string.xml
<字符串名称=TAB1>我选项卡标签< /串>
我一直在寻找,并试图现在摸不着头脑了好几个小时。我可能只是使图标变小的大约两分钟,但我很喜欢它们的大小。
任何人都可以建议最好的方式做简单格式化选项卡标签?
解决方案 tabHost.addTab(tabHost.newTabSpec(TAB1)。setContent(
新的意图(这一点,DealCities.class))setIndicator(prepareTabView(优惠,R.drawable.deal)))。
其中prepareTabView是一种方法。在这些方法充气景色,并添加图片和文字如下:
私人查看prepareTabView(字符串文本,诠释渣油){
查看查看= LayoutInflater.from(本).inflate(R.layout.tabs,NULL);
ImageView的IV =(ImageView的)view.findViewById(R.id.TabImageView);
TextView的电视=(TextView中)view.findViewById(R.id.TabTextView);
iv.setImageResource(渣油);
tv.setText(文本);
返回查看;
}
在哪里标签是放大的视图和它的XML如下:
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直机器人:ID =@ + ID / TabLayout机器人:背景=@可绘制/ tab_bg_selector
机器人:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT
机器人:重力=中心
填充=5dip>
< ImageView的机器人:ID =@ + ID / TabImageView机器人:SRC =@可绘制/图标
机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT/>
< TextView的机器人:ID =@ + ID / TabTextView机器人:文本=文本
机器人:paddingTop =5dip机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT机器人:文字颜色=@彩色/黑白
机器人:textAppearance =@风格/ TabTextViewStyle/>
< / LinearLayout中>
现在你可以让你垫,只要你喜欢。
I just started programming for android. I'm using a tab based layout in my app. I would like to put some padding around the tab label so that it's not so close to the icon.
here is how the label is put in:
in main.java
spec = tabHost.newTabSpec("tab1").setIndicator(this.getString(R.string.tab1), res.getDrawable(R.drawable.ic_tab1)).setContent(intent);
and in string.xml
<string name="tab1">my tab label</string>
I've been searching and trying to figure this out for several hours now. I could just make the icons smaller in about two minutes but I like their size.
Can anyone suggest the best way to do simple formatting to the tab label?
解决方案tabHost.addTab(tabHost.newTabSpec("tab1").setContent(
new Intent(this, DealCities.class)).setIndicator(prepareTabView("Deals",R.drawable.deal)));
Where prepareTabView is a method.. In these method Inflate a view and add Image and Text as follows :
private View prepareTabView(String text, int resId) {
View view = LayoutInflater.from(this).inflate(R.layout.tabs, null);
ImageView iv = (ImageView) view.findViewById(R.id.TabImageView);
TextView tv = (TextView) view.findViewById(R.id.TabTextView);
iv.setImageResource(resId);
tv.setText(text);
return view;
}
Where tabs is the inflated view and its xml as follows :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:id="@+id/TabLayout" android:background="@drawable/tab_bg_selector"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:gravity="center"
padding="5dip">
<ImageView android:id="@+id/TabImageView" android:src="@drawable/icon"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:id="@+id/TabTextView" android:text="Text"
android:paddingTop="5dip" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="@color/black"
android:textAppearance="@style/TabTextViewStyle" />
</LinearLayout>
Now you can make Your Paddings as you like..