概要
TabHostを使ってタブを実装し、そのタブに対して9patchを適用した画像を使用した場合に画像が崩れる現象が発生した。
詳細
タブに対する画像設定は以下の通り。
タブ設定処理
TabHost tabHost = (TabHost)parentView.findViewById(android.R.id.tabhost);
tabHost.setup();
TabSpec tabSpec = tabHost.newTabSpec(TAB_ID);
TabView tabView = new TabView(context, tab_layout);
tsMyPlan.setIndicator(tabView);
tsMyPlan.setContent(R.id.tab);
tabHost.addTab(tabSpec);
tab_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:orientation="vertical"
android:background="@drawable/tab">
</LinearLayout>
drawable/tab
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_selected="true"
android:drawable="@drawable/tab_active"/>
<item
android:state_selected="false"
android:drawable="@drawable/tab_deactive"></item>
</selector>
以下の端末で現象を確認
Galaxy NEXUS OS4.2.2
解決法
すべてのタブに設定する画像の9patch設定を同じにする。
いろいろ、試行錯誤しましたが結論はこれでした。
しかし、Draw9Patchは使いづらいので書き直すのが大変でした。