当我尝试向布局添加超过 4 张图像时,应用程序崩溃
When I try to add more than 4 images to the layout, the app crashes
我正在制作一个简单的 table 布局,每行显示两张图片。当我添加四个适合单个屏幕的图像时,它的工作正常,但是当我添加更多行和其他图像时,应用程序崩溃并说应用程序已停止工作。我还没有开始接触 mainActivity.class 文件。只是做一个布局给我这个错误!
这里是 xml 代码:
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<TableRow>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView1"
android:layout_row="0"
android:layout_column="0"
android:src="@drawable/img1"/>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView2"
android:layout_row="0"
android:layout_column="1"
android:src="@drawable/img2"/>
</TableRow>
<TableRow>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView3"
android:layout_row="1"
android:layout_column="0"
android:src="@drawable/img3"/>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView4"
android:layout_row="1"
android:layout_column="1"
android:src="@drawable/img4"/>
</TableRow>
<TableRow>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView5"
android:layout_row="2"
android:layout_column="0"
android:src="@drawable/img5"/>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView6"
android:layout_row="2"
android:layout_column="1"
android:src="@drawable/img6"/>
</TableRow>
<TableRow>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView7"
android:layout_row="3"
android:layout_column="0"
android:src="@drawable/img7"/>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView8"
android:layout_row="3"
android:layout_column="1"
android:src="@drawable/img8"/>
</TableRow>
<TableRow>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView9"
android:layout_row="4"
android:layout_column="0"
android:src="@drawable/img9"/>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView10"
android:layout_row="4"
android:layout_column="1"
android:src="@drawable/img10"/>
</TableRow>
</TableLayout>
</RelativeLayout>
错误日志:
06-21 13:42:16.190 1542-1551/android.process.acore E/StrictMode﹕ A
resource was acquired at attached stack trace but never released. See
java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at android.os.ParcelFileDescriptor.
您必须为此目的使用库,因为在将图像添加到您的应用程序时处理内存是一项艰巨的任务,您不想自己做。
值得庆幸的是,Picasso Library 对此非常有用,您应该更好地阅读它并在您的应用程序中使用它。
这是给图书馆的link:
我正在制作一个简单的 table 布局,每行显示两张图片。当我添加四个适合单个屏幕的图像时,它的工作正常,但是当我添加更多行和其他图像时,应用程序崩溃并说应用程序已停止工作。我还没有开始接触 mainActivity.class 文件。只是做一个布局给我这个错误!
这里是 xml 代码:
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<TableRow>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView1"
android:layout_row="0"
android:layout_column="0"
android:src="@drawable/img1"/>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView2"
android:layout_row="0"
android:layout_column="1"
android:src="@drawable/img2"/>
</TableRow>
<TableRow>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView3"
android:layout_row="1"
android:layout_column="0"
android:src="@drawable/img3"/>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView4"
android:layout_row="1"
android:layout_column="1"
android:src="@drawable/img4"/>
</TableRow>
<TableRow>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView5"
android:layout_row="2"
android:layout_column="0"
android:src="@drawable/img5"/>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView6"
android:layout_row="2"
android:layout_column="1"
android:src="@drawable/img6"/>
</TableRow>
<TableRow>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView7"
android:layout_row="3"
android:layout_column="0"
android:src="@drawable/img7"/>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView8"
android:layout_row="3"
android:layout_column="1"
android:src="@drawable/img8"/>
</TableRow>
<TableRow>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView9"
android:layout_row="4"
android:layout_column="0"
android:src="@drawable/img9"/>
<ImageView
android:layout_width="150dp"
android:layout_height="200dp"
android:id="@+id/imageView10"
android:layout_row="4"
android:layout_column="1"
android:src="@drawable/img10"/>
</TableRow>
</TableLayout>
</RelativeLayout>
错误日志:
06-21 13:42:16.190 1542-1551/android.process.acore E/StrictMode﹕ A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called at dalvik.system.CloseGuard.open(CloseGuard.java:184) at android.os.ParcelFileDescriptor.
您必须为此目的使用库,因为在将图像添加到您的应用程序时处理内存是一项艰巨的任务,您不想自己做。
值得庆幸的是,Picasso Library 对此非常有用,您应该更好地阅读它并在您的应用程序中使用它。
这是给图书馆的link: