English 中文(简体)
如果 MinSdkVersion > 10, 为什么未显示元件Tab 中的图像?
原标题:Why are the images in WidgetTab not shown if minSdkVersion>10?

我一直在尝试用 3 Tabs 创建一个简单的 < code> Tabactivity 。 如果我将 < code> 和roid: minSdkVersion="11" 放到宣言文件中, 图标将不显示。 如果我设置“ minSdkVersion=” 10, 图标将全部完好 。

I have looked high and low, but I have not been able to determine what is wrong.
I have put the same images in the seemingly appropriate resource directories:

res/drawable-hdpi-v5
res/drawable-ldpi-v5
res/drawable-mdpi-v5
res/drawable-xhdpi-v5

代码很简单:

import android.app.TabActivity;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabWidget;

public class Review extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TabHost tabs = getTabHost();
        getLayoutInflater().inflate(R.layout.main, 
                                    tabs.getTabContentView(), true);
        Resources resources=getResources();
        Log.d("testing", String.format("icon: %d.%d",
                    resources.getDrawable(R.drawable.review).getIntrinsicWidth(), 
            resources.getDrawable(R.drawable.review).getIntrinsicHeight()));
        TabHost.TabSpec details = tabs.newTabSpec("review"). setContent(R.id.review). 
                setIndicator(getString(R.string.review), 
                        resources.getDrawable(R.drawable.review));        
        TabHost.TabSpec gallery=tabs.newTabSpec("gallery").setContent(R.id.photos)
                .setIndicator(getString(R.string.gallery), 
                        resources.getDrawable(R.drawable.photos));
        TabHost.TabSpec reservation=tabs.newTabSpec("reservation").
             setContent(R.id.reservation)
                .setIndicator(getString(R.string.reservation), 
                        resources.getDrawable(R.drawable.reservation));
        tabs.addTab(details);
        tabs.addTab(gallery);
        tabs.addTab(reservation);    
    }
}

在调查这个问题时,我所看到的唯一差异是,在2.0和3.0下,Android使用 RelativeLayout ,而不是在2.0执行中使用 LineearLayout

只要确定正在找到图标图像, 上面的 Log.d 显示 :

icon: 32.32 , 因为它应该如此。

为何从2.0机器人变成3.0机器人???? 我希望有人碰过这个,而且很明显。 非常感谢您的帮助!

-- -- 更新:

今天我发现,随着我更仔细地观察了当这个代码是为机器人3.0+而建时实际发生的情况,我了解到,当每个 SetIndeicator(字符串、可绘图) 被调用时,产生的 ImageView < /code> (代码>SetIndeicator(字符串、可绘图) 实际上是从未设置的,而且实际上是 NULL ( ImageView.mDrowable ) ( < code>ImageView.mnull )和 > INISBle

如果我强行设定这些绘图可设定, 调用 ImaageView.set Visibliity(View. Visible) 就会出现。 然而,在2.0和2.0下,它们似乎堆叠了上面的图像和下面的文字,如:

<image>
<text>

和3.0,它们(在被强迫如上)并肩出现,如:

因此,事情似乎发生了很大变化,我需要更仔细地调查3.0和3.0的变化。

继续收听更多...

- 最后更新:

最终,我放弃了这条途径,决定这种做事方式改变了,现在也许已经折旧了,还有其他更好的方法来这样做,而图标的风格也有点老了。

问题回答

奇怪,这解决了问题

    //bmOptions.inSampleSize = 1;
    //or better
    bmOptions.inScaled = false;

more at: https://stackoverflow.com/a/12088287/1320686





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签