【转】在Titanium开发Android应用时实现底部tabbar
?
- <?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:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="0dp"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="0dp" android:layout_weight="1"/> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0"/> </LinearLayout> </TabHost>
然后再重新clean后再次运行,效果如下:

其实这中间的道理很简单,就是用我们的布局文件覆盖了Titanium既存的布局文件,让应用使用我们的布局文件来运行代码。
关于这里为什么一定要命名为titanium_tabgroup.xml,可以参看源代码的TiTabActivity.java74行-77行
?


- int layoutResId = getResources().getIdentifier("titanium_tabgroup", "layout", getPackageName());if (layoutResId == 0) {throw new IllegalStateException("titanium_tabgroup layout resource not found. TabGroup cannot be created.");}?


- <?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:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="0dp"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="0dp" android:layout_weight="1"/> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="0"/> </LinearLayout> </TabHost>
大小: 13.2 KB