मुझे अपनी टैबविड्ज पृष्ठभूमि छवियों को स्केल करने की आवश्यकता है ताकि वे पहलू अनुपात बनाए रखें।
मैं TabWidget के साथ एक टैबहोस्ट का उपयोग कर रहा हूं। मैं फिर छवियों को सेट करने के लिए setBackgroundDrawable का उपयोग कर रहा हूँ।टैबहोस्ट/टैबविड्ज - स्केल पृष्ठभूमि छवि?
मुझे यहां एक करीबी उत्तर मिला - Background in tab widget ignore scaling। हालांकि, मुझे यकीन नहीं है कि नया ड्रायबल कोड कहां जोड़ना है। (HelloTabWidget उदाहरण के साथ काम करते हुए, मेरे मॉड्यूल में से कोई भी रिलेवेटिवआउट का उपयोग नहीं करता है, और मुझे "टैबकंटेंट" के लिए कोई लेआउट दिखाई नहीं देता है।)
मुझे यह थ्रेड भी मिला - Android: Scale a Drawable or background image?। इसके अनुसार, ऐसा लगता है कि मुझे अपनी छवियों को पूर्व-स्केल करना होगा, जो उन्हें स्केल करने योग्य बनाने के पूरे उद्देश्य को हरा देता है।
मुझे एक और धागा भी मिला जहां किसी ने ड्रायबल क्लास को उप-वर्गीकृत किया ताकि यह स्केल न हो, या यह ठीक से स्केल करेगा। मुझे अब यह नहीं मिल रहा है, लेकिन ऐसा लगता है कि जब आप 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 कोशिश की, लेकिन वे बहुत छोटा किया जा रहा है हवा।
तो, इस बारे में जाने का सबसे अच्छा तरीका क्या है?