Cuối cùng tôi quản lý để có một tab có kích thước khác nhau sử dụng ToggleButton.
XML của tôi là như thế này
<LinearLayout
android:id="@+id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@id/header"
>
<ToggleButton
android:id="@+id/tab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/icon_home"
android:textOn=""
android:textOff=""
android:background="@drawable/tabselector"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:layout_weight="0"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/top_menubar_separator" />
<ToggleButton
android:id="@+id/tab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/icon_store"
android:textOn="Store"
android:textOff="Store"
android:background="@drawable/tabselector"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:layout_weight="2"
/>
đâu mỗi ToggleButton là một tab. Bí quyết ở đây là sử dụng trọng lượng để mở rộng các tab để hoàn toàn lấp đầy màn hình.
Các teab_selector.xml trông như thế này
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/top_menubar_selected"
android:state_pressed="true"
/>
<item android:drawable="@drawable/top_menubar_selected"
android:state_checked="true"
/>
<item android:drawable="@drawable/top_menubar_1px" />
</selector>
tôi vẫn cần phải mã logic cho un-bấm một nút khi một cái mới được chọn và khởi động một ý định với ta hoạt động, nhưng có vẻ tốt đẹp cho đến nay .
tôi đang cũng đang tìm kiếm giống nhau, thanh toán này: http://stackoverflow.com/questions/3446722/android-tabhost-problem-setindicator –
Trông thú vị Paresh. Bạn đã thử bất kỳ giải pháp được đề xuất nào (Style hoặc ghi đè TabHost)? Ngay bây giờ tôi đang xem xét vấn đề này và suy nghĩ cách tiếp cận tốt nhất/nhanh nhất là tạo các tab của riêng chúng ta (với các nút và người nghe). – momo