【发布时间】:2011-04-23 01:05:10
【问题描述】:
我正在尝试来自官方开发者网站的 TabLayout 教程。我没有照原样复制粘贴它,并且对 tut 中的拼写错误进行了一些小的更改和更正。
package com.org.example;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class HalloTabLayout extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent;
TabHost tabhost = getTabHost();
TabHost.TabSpec tabspec;
Resources res = getResources();
//For the Family Tab
//Intent
intent = new Intent().setClass(this, FamilyLayout.class);
//Setting the tab
tabspec = tabhost.newTabSpec("family").setIndicator("Family", res.getDrawable(R.drawable.tab_spec)).setContent(intent);
tabhost.addTab(tabspec);
//Default tab to display
tabhost.setCurrentTabByTag("family");
}
}
作为第一步并确保代码正确,我希望显示一个单一选项卡。
我将 FamilyLayout 活动添加到 AndroidManifest.xml 文件并在此处进行了建议的更改。 Issues with Android TabHost Example
但应用程序在模拟器中运行时不断崩溃。任何帮助将非常感激。
[解决方案:] 我使用了高分辨率和大小(3.5mb)的 .jpeg,这导致了麻烦。我将其更改为较低分辨率、尺寸的图片,它可以正常工作。我通过反复试验发现超过 1600*900 的图像会使应用程序崩溃。不是一个确切的统计数据,但它可能会有所帮助。
【问题讨论】:
-
如果您的应用程序崩溃,您需要从 LogCat 发布堆栈跟踪。
-
我让应用程序正常工作。问题出在我用作可绘制对象的图片上。我使用了.jpg,这是麻烦的根源。使用 .png 类型,它没有任何问题..
-
有趣的是,png 有效,但 jpg 无效。顺便说一句:把你的决议作为答案,然后关闭它。 (我只是想回复另一个带有代码的选项卡示例在这里:stackoverflow.com/questions/3103062/…,但您自己已经找到了问题的答案:)
标签: android