3

所以基本上,我有一个可以在谷歌提供的所有设备和模拟器上运行的应用程序。但是有一些人报告没有背景图像,这使得文本不可读。请帮忙,我不知道应用程序哪里出错了。

这是我的 FragmentActivity 文件(基本部分)

public class MainActivity extends FragmentActivity{

    private FragmentTabHost mTabHost;

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);


        Bundle b1 = new Bundle();
        b1.putInt("tabId",111);

        Bundle b2 = new Bundle();
        b2.putInt("tabId",222);


        final FragmentManager fm = getSupportFragmentManager();

        mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
        mTabHost.setup(this, fm, R.id.realtabcontent);

        mTabHost.addTab(mTabHost.newTabSpec("main").setIndicator("MAIN"), TabContentFragment.class, b1);
        mTabHost.addTab(mTabHost.newTabSpec("massReading").setIndicator("MASS READING"), TabContentFragment.class, b2);        

        TabWidget tw = mTabHost.getTabWidget(); //this tabwidget is generated after "addTab", the one from layout is not doing anything        
        tw.setVisibility(0x00000008); // = "GONE"
    }
}

和“activity_main”布局文件

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg"> *******//This is the background image I need to display********

    <LinearLayout 
        android:id="@+id/top"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/padding"
        android:gravity="center"
        android:background="@android:color/transparent"
        >
        <Button
            android:id="@+id/back"
            style="@style/btn"
            android:background="@drawable/back"
            />   
        <TextView
            android:id="@+id/title"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:textStyle="bold"
            style="@style/title"
            android:gravity="center"
            />  
        <Button
            android:id="@+id/down"
            style="@style/btn"
            android:background="@drawable/decrease"     
            android:layout_marginRight="15dp"  
            />                                      
        <Button
            android:id="@+id/up"
            style="@style/btn"
            android:background="@drawable/increase"                         
            />
    </LinearLayout>

    <android.support.v4.app.FragmentTabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:background="@android:color/transparent"
        >

        <TabWidget
            android:id="@android:id/tabs"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp"
            />

        <FrameLayout
            android:id="@+id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />

    </android.support.v4.app.FragmentTabHost>

    <RadioGroup 
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:orientation="horizontal"
        android:id="@+id/rg"
        >
        <RadioButton 
            android:id="@+id/main" 
            style="@style/rb"
            android:drawableTop="@drawable/reflection"
            android:text="@string/rb_left"
            />
        <RadioButton
            android:id="@+id/mr"
            style="@style/rb"
            android:drawableTop="@drawable/readings"
            android:text="@string/rb_right"
            />
    </RadioGroup>

</LinearLayout>

和只有 2 个 webviews 的片段文件

public class TabContentFragment extends Fragment {

    WebView wv;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (container == null) {
            return null;
        }


        Bundle b = getArguments();
        int tabId = b.getInt("tabId");

        wv = (WebView)inflater.inflate(R.layout.tab_content, container, false);

        wv.setId(tabId); 
        wv.setVerticalScrollBarEnabled(false);
        wv.setBackgroundColor(0);

        if(tabId==111)
        {   

            String htmlString = "<html xmlns='http://www.w3.org/1999/xhtml'>stuff</html>";          
            wv.loadDataWithBaseURL("",htmlString, "text/html", "UTF-8", "");
        }
        else
        {
            String htmlString = "<html xmlns='http://www.w3.org/1999/xhtml'>stuff</html>";          
            wv.loadDataWithBaseURL("",htmlString, "text/html", "UTF-8", "");
        }

        return wv;
    }
}
4

1 回答 1

1

检查抱怨没有位图显示的设备的详细信息,查找 VM 预算。如果设备没有足够的内存来保存位图,则可以简单地将位图设置为空(或无背景)。鉴于您的症状,我会说这是问题所在。

于 2014-03-15T22:19:49.417 回答