Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Android应用程序上显示多个图像_Java_Android_Xml_Android Layout - Fatal编程技术网

Java 在Android应用程序上显示多个图像

Java 在Android应用程序上显示多个图像,java,android,xml,android-layout,Java,Android,Xml,Android Layout,我创建了一个Android应用程序,其中包含10个文本视图框,我给每个框提供了不同的背景。当我在我的设备上运行应用程序时,如果我使用10种不同的背景,它就会崩溃。如果我只使用8种不同的背景来填充10个文本视图框,该应用程序运行良好。为什么会发生这种情况?我如何修复它 编辑: 很抱歉没有添加代码,但下面是xml文件。请注意,我为从img1到img10的每个文本视图添加了一个背景。如果我把它加载到我的设备上,程序就会崩溃。如果我将img9更改为img7,将img10更改为img7,那么它将正常工作。

我创建了一个Android应用程序,其中包含10个文本视图框,我给每个框提供了不同的背景。当我在我的设备上运行应用程序时,如果我使用10种不同的背景,它就会崩溃。如果我只使用8种不同的背景来填充10个文本视图框,该应用程序运行良好。为什么会发生这种情况?我如何修复它

编辑: 很抱歉没有添加代码,但下面是xml文件。请注意,我为从img1到img10的每个文本视图添加了一个背景。如果我把它加载到我的设备上,程序就会崩溃。如果我将img9更改为img7,将img10更改为img7,那么它将正常工作。我不知道为什么会发生这种情况,我检查了尺寸。它们加起来不到16MB

所以,请原谅我的无知。我是android应用程序创建新手,但我发现抛出了OutOfMemory异常。这不影响大小,b/c我的图像都在100KB以下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#8ad0e8"
    tools:context=".Adamantium1" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="0dp"
        android:weightSum="3" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="fill_parent"
            android:layout_height="90dp"
            android:layout_weight="1"
            android:gravity="center"
            android:textSize="60sp"
            android:background="@drawable/img1"
            android:textStyle="bold"
            android:text="9" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="fill_parent"
            android:layout_height="90dp"
            android:layout_weight="1"
            android:gravity="center"
            android:textSize="60sp"
            android:textStyle="bold"
            android:background="@drawable/img2"
            android:text="9" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="fill_parent"
            android:layout_height="90dp"
            android:gravity="center"
            android:textSize="60sp"
            android:textStyle="bold"
            android:background="@drawable/img3"
            android:layout_weight="1"
            android:text="9" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/linearLayout1"
        android:layout_below="@+id/linearLayout1"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="0dp" >

        <TextView
            android:id="@+id/textView4"
            android:layout_width="fill_parent"
            android:layout_height="90dp"
            android:gravity="center"
            android:textSize="60sp"
            android:textStyle="bold"
            android:background="@drawable/img4"
            android:layout_weight="1"
            android:text="9" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="fill_parent"
            android:layout_height="90dp"
            android:layout_weight="1"
            android:gravity="center"
            android:textSize="60sp"
            android:textStyle="bold"
            android:background="@drawable/img5"
            android:text="9" />

        <TextView
            android:id="@+id/textView6"
            android:layout_width="fill_parent"
            android:layout_height="90dp"
            android:layout_weight="1"
            android:gravity="center"
            android:textSize="60sp"
            android:textStyle="bold"
            android:background="@drawable/img6"
            android:text="9" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/linearLayout2"
        android:layout_below="@+id/linearLayout2"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="0dp" >

        <TextView
            android:id="@+id/textView7"
            android:layout_width="fill_parent"
            android:layout_height="90dp"
            android:layout_weight="1"
            android:gravity="center"
            android:textSize="60sp"
            android:textStyle="bold"
            android:background="@drawable/img7"
            android:text="9" />

        <TextView
            android:id="@+id/textView8"
            android:layout_width="fill_parent"
            android:layout_height="90dp"
            android:layout_weight="1"
            android:gravity="center"
            android:textSize="60sp"
            android:textStyle="bold"
            android:background="@drawable/img8"
            android:text="9" />

        <TextView
            android:id="@+id/textView9"
            android:layout_width="fill_parent"
            android:layout_height="90dp"
            android:layout_weight="1"
            android:gravity="center"
            android:textSize="60sp"
            android:textStyle="bold"
            android:background="@drawable/img9"
            android:text="7" />
    </LinearLayout>

    <EditText
        android:id="@+id/editText1"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView10"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:ems="1"
        android:inputType="numberPassword" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView10"
        android:layout_width="fill_parent"
        android:layout_height="90dp"
        android:layout_below="@+id/linearLayout3"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:text="9"
        android:textSize="60sp"
        android:background="@drawable/img10"
        android:textStyle="bold" />

    <Button
        android:id="@+id/EnterPass"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="90dp"
        android:layout_height="40dp"
        android:layout_alignBottom="@+id/editText1"
        android:layout_marginLeft="21dp"
        android:layout_toRightOf="@+id/editText1"
        android:text="Enter" />

</RelativeLayout>

可能是您的图像太大,无法保存在android中每个应用程序的堆中,在4.2版中为16 MB
可能的解决方案是减小图像大小

这是我能从你在这里发布的问题中分辨出的最好的结果。

请发布你的代码请发布代码,我正在搜索“android位图内存不足”