<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>
尝试在运行时通过在TabHost的onTabChanged()上使用以下代码更改textview(make_fav)图像。基本上我想在用户点击标签时改变图像。图像在tabhost中运行时在textview中拉伸
LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
tabHost.getCurrentTabView().setBackgroundResource(R.drawable.prev_button);
tabHost.getCurrentTabView().setLayoutParams(params);
问:我怎样才能获得9修补图像不拉伸,即使它正确显示在XML?
使用选择器在运行时更改图像 – juned 2013-05-02 13:13:21