【问题标题】:My app crashes after starting activity with scrollview使用滚动视图启动活动后,我的应用程序崩溃
【发布时间】:2018-08-13 02:59:27
【问题描述】:

我的 Android 应用程序有问题。在应用程序中有一个 xml 文件,其中包含一个 RelativeLayout 和一个滚动视图。在滚动视图中有一些我想显示的图像。问题是,当滚动视图中有 3 个 ImageView 时,活动和 xml 页面工作正常,但是当我添加第 4 个 ImageView 时,当我启动活动时应用程序崩溃。

我在下面发布代码,添加第 4 个 ImageView 时会出现问题。有什么想法吗?

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
    android:orientation="vertical"
    android:alwaysDrawnWithCache="true"
    android:fadeScrollbars="true"
    android:verticalScrollbarPosition="right">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:gravity="center"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/Double_image"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:scaleType="centerCrop"
            android:src="@drawable/trouble" />

        <ImageView
            android:id="@+id/Secret_image"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_below="@+id/Double_image"
            android:scaleType="centerCrop"
            android:src="@drawable/secret" />

        <ImageView
            android:id="@+id/kidnap_image"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_below="@id/Secret_image"
            android:scaleType="centerCrop"
            android:src="@drawable/kidnap" />

        <ImageView
                android:id="@+id/kidnap2_image"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:layout_below="@id/kidnap_image"
                android:scaleType="centerCrop"
                android:src="@drawable/kidnap2" />


    </RelativeLayout>
</ScrollView>

注意:与此 xml 文件相关联的活动没有任何功能。

这里是上面xml连接的Activity类。

package com.example.thomas.firstcue;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class RoomsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rooms);
    }
}

我通过单击按钮和函数 StartActivity 从 Main 启动活动

  rooms_but.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View view) {

            startActivity(intentrooms);

        }

    });

应用程序在手机上正常启动,但当我按下按钮启动活动时,应用程序崩溃。 On phone error

【问题讨论】:

  • 添加崩溃日志,同时添加你的java类
  • 发布您的堆栈跟踪.. 我最好的猜测是 outOfMemoryError 因为高分辨率图像..
  • 您的第四张图片是否 (v24) 在像 kidnap.png(v24) 这样的 drawble 文件夹中?
  • @Milan 是正确的,首先粘贴您的错误日志
  • 我考虑了您的 cmets,并按照您的建议进行了更改。

标签: android xml android-activity scrollview


【解决方案1】:

应用程序崩溃的一种可能性是您位于drawable 中的第四张图片有v24 就像kidnap.png(v24) 一样

所以首先从drawable文件夹(..\app\src\main\res\drawable-v24)中删除这个图像,然后再次将其粘贴到drawable(..\app\src\main\res\drawable)文件夹中只有kidnap.png

【讨论】:

    猜你喜欢
    • 2019-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-19
    • 1970-01-01
    相关资源
    最近更新 更多