As the title stated, my problem is related to the error. I have set 3 layout that uses the same background but there's only 1 layout that keeps producing this error. The error started when I set the background. Without the background, it can run with no problem. But the one that I want to solve is how to fix the out of memory error and why does this layout produce the error, while the other two doesn't. The code is pretty much the same.
This is the layout that produces the error.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/seabg">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
app:srcCompat="@drawable/f1"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:text="CLICK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="177dp"
android:id="@+id/btnf"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
app:srcCompat="@drawable/ferry"
android:id="@+id/imageView1"
android:layout_marginBottom="36dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Meanwhile, this is the one that can be run normally without the error. (It should be two layouts, saving some space because the code looks exactly the same only the first ImageView
is different.)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/seabg">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
app:srcCompat="@drawable/y1"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:text="CLICK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="177dp"
android:id="@+id/btny"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
app:srcCompat="@drawable/yacht"
android:id="@+id/imageView1"
android:layout_marginBottom="36dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Edit: This is my activity for the one that produce the error.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_f);
final MediaPlayer fSound = MediaPlayer.create(this, R.raw.ferry);
btnf = (Button) findViewById(R.id.btnf);
btnf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
fSound.start();
}
});
}
And this is the one that can be run with no problem.
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_y);
final MediaPlayer ySound = MediaPlayer.create(this, R.raw.yacht);
btny = (Button) findViewById(R.id.btny);
btny.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ySound.start();
}
});
}