android - Image is stretched in textview on runtime in tabhost -


<tabhost     android:id="@android:id/tabhost"     android:layout_width="fill_parent"     android:layout_height="fill_parent" >      <linearlayout         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:orientation="vertical" >          <tabwidget             android:id="@android:id/tabs"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:layout_marginleft="0dip"             android:layout_marginright="0dip" >              <textview                 android:id="@+id/view_all"                 android:layout_width="wrap_content"                 android:layout_height="fill_parent"                 android:tag="tab0"                 android:text="view all" />              <textview                 android:id="@+id/favourite"                 android:layout_width="wrap_content"                 android:layout_height="fill_parent"                 android:tag="tab1"                 android:text="favourite" />              <textview                 android:id="@+id/make_fav"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:tag="tab2"                 android:background="@drawable/prev_button" />         </tabwidget>          <framelayout             android:id="@android:id/tabcontent"             android:layout_width="match_parent"             android:layout_height="wrap_content" >          </framelayout>     </linearlayout> </tabhost> 

trying change textview(make_fav) image @ runtime using below code on ontabchanged() of tabhost. want change image when user clicks on tab.

layoutparams params = new linearlayout.layoutparams(layoutparams.wrap_content, layoutparams.wrap_content); tabhost.getcurrenttabview().setbackgroundresource(r.drawable.prev_button); tabhost.getcurrenttabview().setlayoutparams(params); 

question: how can 9-patch image not stretch, though displays in xml?

create xml below

tab_image.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">     <item android:state_pressed="true"          android:drawable="@drawable/tab_pressed_image" />     <item android:state_focused="true"         android:drawable="@drawable/tab_pressed_image" />     <item         android:drawable="@drawable/simple_image" /> </selector> 

put xml under drawable directory , set image background of tab.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -