TabHost / TabWidget - Skala Hintergrundbild?

Ich den Maßstab meiner TabWidget hintergrund Bilder, so dass Sie das Seitenverhältnis beizubehalten.

Ich bin mit einem TabHost mit einem TabWidget. Ich bin dann mit setBackgroundDrawable einstellen der Bilder.

Fand ich eine schließen-Antwort hier - Hintergrund in der tab-widget ignorieren Skalierung. Allerdings bin ich mir nicht sicher, genau dort, wo hinzufügen der neuen Drawable-code. (Arbeiten mit dem HelloTabWidget Beispiel keines meiner Module verwenden, RelativeLayout, und ich kann nicht sehen, layout für "tabcontent".)

Ich auch diesen thread gefunden - Android: Skala eine Drawable-oder hintergrund-Bild?. Laut, es klingt wie, würde ich die pre-scale meinen Bildern, die Niederlagen der ganze Zweck, dass Sie skalierbar.

Ich fand auch einen anderen thread, wo jemand Unterklassen der Klasse Drawable, so würde es entweder nicht skalieren, oder es würde korrekt skaliert. Ich finde es jetzt nicht, aber das scheint wie eine MENGE, um durch zu gehen, wenn Sie sollte nur in der Lage sein, etwas einfaches zu machen wie mTab.setScaleType(centerInside).

Hier ist mein code:

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>

Haupttätigkeit:

        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));
}

Ich habe auch versucht 9patch Bilder, aber Sie wind-up wird zu klein.

So, was ist der beste Weg zu gehen über diese?

InformationsquelleAutor user359519 | 2010-12-16
Schreibe einen Kommentar