가로 세로 비율을 유지하기 위해 TabWidget 배경 이미지의 크기를 조정해야합니다.
TabWidget과 함께 TabHost를 사용하고 있습니다. 그런 다음 setBackgroundDrawable을 사용하여 이미지를 설정합니다.TabHost/TabWidget - 스케일 배경 이미지?
여기에 가까운 대답을 찾았습니다 - Background in tab widget ignore scaling. 그러나 새로운 Drawable 코드를 추가 할 위치가 확실하지 않습니다. (HelloTabWidget 예제로 작업하면 어떤 모듈도 RelativeLayout을 사용하지 않으며 "tabcontent"레이아웃이 보이지 않습니다.)
이 스레드는 - Android: Scale a Drawable or background image?입니다. 그것에 따르면, 이미지를 미리 조절해야만하는 것처럼 들리 겠지만, 이미지를 확장 할 수있는 전체 목적에 어긋납니다.
또 다른 스레드가 Drawable 클래스를 서브 클래 싱하여 크기를 조정하지 않거나 제대로 확장 할 수있는 스레드를 발견했습니다. 지금은 찾을 수 없지만 mTab.setScaleType (centerInside)과 같은 간단한 작업을 수행 할 수 있어야 할 때가 많습니다.
여기 내 코드입니다 :
main.xml에 :
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/main_background">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
</LinearLayout>
</TabHost>
주요 활동 :
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
TabHost changedTabHost = getTabHost();
TabWidget changedTabWidget = getTabWidget();
View changedView = changedTabHost.getTabWidget().getChildAt(0);
public void onTabChanged(String tabId) {
int selectedTab = changedTabHost.getCurrentTab();
TabWidget tw = getTabWidget();
if(selectedTab == 0) {
//setTitle("Missions Timeline");
View tempView = tabHost.getTabWidget().getChildAt(0);
tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_timeline_on));
tempView = tabHost.getTabWidget().getChildAt(1);
tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_map_off));
tempView = tabHost.getTabWidget().getChildAt(2);
tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_search_off));
tempView = tabHost.getTabWidget().getChildAt(3);
tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_news_off));
tempView = tabHost.getTabWidget().getChildAt(4);
tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_license_off));
//ImageView iv = (ImageView)tabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.icon);
//iv.setImageDrawable(getResources().getDrawable(R.drawable.tab_timeline_on));
//iv = (ImageView)tabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.icon);
//iv.setImageDrawable(getResources().getDrawable(R.drawable.tab_map_off));
} else if (selectedTab == 1) {
//setTitle("Spinoffs Around You");
View tempView = tabHost.getTabWidget().getChildAt(0);
tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_timeline_off));
tempView = tabHost.getTabWidget().getChildAt(1);
tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_map_on));
tempView = tabHost.getTabWidget().getChildAt(2);
tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_search_off));
tempView = tabHost.getTabWidget().getChildAt(3);
tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_news_off));
tempView = tabHost.getTabWidget().getChildAt(4);
tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_license_off));
}
나는 또한 이미지를 9patch했지만, 그들은 너무 작은 것을 바람.
그래서이 문제를 해결하는 가장 좋은 방법은 무엇입니까?