有誰知道這會導致什麼?標籤之間的間距不一致
我創建了一個自定義選項卡的佈局和我要麼需要的間距或沒有,只是一致性。理想情況下,我不想使用間距,但我已經閱讀過,這可能不適用於Android的操作欄。
這是我使用的XML代碼:
public class Tabs extends TabActivity {
private static final Properties properties = Properties.getInstance();
TabHost mTabHost;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
mTabHost = getTabHost();
addTab(getString(R.string.text_tabs_1), R.drawable.listing_tab_active, new Intent(this, Main.class), R.drawable.listing_tab_inactive);
addTab(getString(R.string.text_tabs_2), R.drawable.keyword_tab_active, new Intent(this, Keywords.class), R.drawable.keywords_tab_inactive);
addTab(getString(R.string.text_tabs_3), R.drawable.saved_tab_active, new Intent(this, Saved.class), R.drawable.saved_tab_inactive);
}
private void addTab(String label, int drawableId, Intent intent, int imageId)
{
TabHost.TabSpec spec = mTabHost.newTabSpec(label);
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tabs_bg, getTabWidget(), false);
((TextView)tabIndicator.findViewById(R.id.tabText)).setText(label);
((ImageView)tabIndicator.findViewById(R.id.tabImage)).setImageResource(imageId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
mTabHost.addTab(spec);
}
}
tabs.xml
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="0dp"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp"
/>
</LinearLayout>
</TabHost>
tabs_bg.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dip"
android:layout_height="55dip"
android:layout_weight="1"
android:orientation="vertical"
android:padding="5dp"
android:background="@drawable/tab_bg_selector"
>
<ImageView android:id="@+id/tabImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
android:layout_alignParentTop="true"
android:paddingBottom="18dip"
/>
<TextView android:id="@+id/tabText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textColor="@drawable/tab_text_selector"
android:gravity="center_vertical|center_horizontal"
android:textSize="12dip"
/>
</RelativeLayout>
tab_bg_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Active tab -->
<item android:state_selected="true" android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/tab_bg_selected" />
<!-- Inactive tab -->
<item android:state_selected="false" android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/tab_bg_unselected" />
<!-- Pressed tab -->
<item android:state_pressed="true" android:drawable="@drawable/tab_bg_focused" />
<!-- Selected tab (using d-pad) -->
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_bg_focused" />
</selector>
tab_bg_selected.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#A8A8A8" android:centerColor="#7F7F7F" android:endColor="#696969" android:angle="-90" />
</shape>
tab_bg_unselected.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#5C5C5C" android:centerColor="#424242" android:endColor="#222222" android:angle="-90" />
</shape>
tab_bg_focused.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:padding="0dp">
<shape>
<gradient
android:startColor="#E77A26"
android:endColor="#E77A26"
android:angle="270" />
<stroke
android:width="3dp"
color="#0F58A7" />
</shape>
</item>
<item android:state_focused="true" android:padding="0dp">
<shape>
<gradient
android:endColor="#0F58A7"
android:startColor="#0F58A7"
android:angle="270" />
<stroke
android:width="3dp"
color="#0F58A7" />
</shape>
</item>
<item android:padding="0dp">
<shape>
<gradient
android:endColor="#0F58A7"
android:startColor="#0F58A7"
android:angle="270" />
<stroke
android:width="3dp"
color="#0F58A7" />
</shape>
</item>
</selector>