0
我正在尋找一些例子,但是當我添加到我的xml它不起作用。有人可以幫助我。無法對齊我的tabhost底部
這是我的XML tabhost
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tabHost">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:gravity="bottom">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_gravity="bottom"/>
</LinearLayout>
</TabHost>
這是與ImageView的和文本視圖選項卡指示器。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:id="@+id/img_tabhost" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/img_tabhost"
android:textSize="15sp"
android:id="@+id/tv_tabhost" />
</RelativeLayout>
,這是我一直在努力
private TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tabHost = getTabHost();
String tabName = "";
addTab(tabName, R.drawable.ic_home);
addTab(tabName, R.drawable.ic_search);
addTab(tabName, R.drawable.ic_notification);
addTab(tabName, R.drawable.ic_profile);
}
private void addTab(String label, int drawableId){
Intent intent = new Intent();
switch (drawableId){
case R.drawable.ic_home:
//label = "Home";
intent = new Intent(this, Map.class);
break;
case R.drawable.ic_search:
//label = "Search";
intent = new Intent(this, Search.class);
break;
case R.drawable.ic_notification:
//label = "Notifications";
intent = new Intent(this, Notifications.class);
break;
case R.drawable.ic_profile:
//label = "Profile";
intent = new Intent(this, Profile.class);
break;
}
// Create the tab hosts
TabHost.TabSpec spec = this.getTabHost().newTabSpec(label);
View tabIndicator = LayoutInflater.from(this).inflate(
R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.tv_tabhost);
title.setText(label);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.img_tabhost);
icon.setImageResource(drawableId);
spec.setContent(intent);
spec.setIndicator(tabIndicator);
tabHost.addTab(spec);
}
有人可以幫我設置我tabhost在底部的類。
android:layout_alignParentBottom:true
不工作