有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java TabHost不在Nexus 7上渲染图像,而是每隔一个设备渲染一次图像

多亏了TabSpec,我想在我的TabHost中显示一个视图,除了Nexus 7,它在我的所有设备上都能工作

Drawable img = getResources().getDrawable(R.drawable.tab_info_icon);
Intent intent = new Intent(context, Actus.class);
setupTab(img, intent);

private void setupTab(final Drawable image, final Intent intent) {
    View tabview = createTabView(mTabHost.getContext(),image, intent);
    TabSpec setContent = mTabHost.newTabSpec("").setIndicator(tabview).setContent(intent);
    mTabHost.addTab(setContent);
}  

private static View createTabView(final Context context, final Drawable image,final Intent intent) {  
    View view = LayoutInflater.from(context).inflate(R.layout.onglet, null);  

    LinearLayout ll = (LinearLayout)view.findViewById(R.id.fondOnglet);
    ll.setBackgroundResource(R.drawable.tab_bg);

    ImageView iv = (ImageView)view.findViewById(R.id.imgOnglet);
    iv.setImageDrawable(image);
    return view;
}

R.drawable。tab_info_图标是一个xml选择器


共 (1) 个答案

  1. # 1 楼答案

    这很奇怪,但Nexus 7不是hdpi或xhdpi,而是tvdpi,所以我创建了一个可绘制的tvdpi目录,并将我的图像放在那里,它可以工作