我正在尝试官方开发者网站上的TabLayout教程。我没有完全复制粘贴,对教程中的一些错别字进行了一些微小的更改和纠正。
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文件中,并根据此处的建议进行了更改。
但是应用程序在模拟器中运行时仍然崩溃。任何帮助将不胜感激。
[解决方案:] 我使用了一个高分辨率和大小(3.5mb)的.jpeg图片,这是问题的原因。我将其更改为低分辨率、小尺寸的图片,就能正常工作了。通过试错,我发现超过1600*900像素的图像会导致应用程序崩溃。虽然不是精确的统计数据,但可能有所帮助。