当我在手机上运行时,我的应用程序崩溃了

时间:2013-04-16 10:14:31

标签: android xml imageview

我刚开始进入Android应用程序编程,我正在学习互联网上的一切。但是当发生这种情况时,很难真正理解每个示例和方法。无论如何,我试图创建一个应用程序,当单击一个按钮时,它会显示倒数计时器从3倒数到1,然后打开一个ImageView。

我在我的XML布局中定义了TextView(用于倒计时),Button和Imageview,但是当我在手机上试用它时应用程序会崩溃。我删除了imageview,现在它启动了 应该按下按钮,显示倒计时。

顺便说一句,当我按下“图形布局”按钮时,图像会显示在那里。

我对ImageView的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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<Button 
    android:id="@+id/btn1"
    android:text="@string/btnMessage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true" />"


<ImageView 
    android:id="@+id/idrink"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_below="@id/btn1"
    android:src="@drawable/idrink"
    android:contentDescription="Underwater Drinking"/>

<TextView
    android:id="@+id/tview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/iview"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="126dp"
    android:textSize="50sp"
    android:visibility="invisible" />

2 个答案:

答案 0 :(得分:2)

我认为问题可能是您尝试设置的ImageView太大了。 “idrink”图像的分辨率和大小是多少?

答案 1 :(得分:0)

当应用程序对对象进行越来越多的引用并且永远不会释放它们时,会发生内存泄漏。

尝试在将图像添加到布局之前调整图像大小。

您可以按照以下方式进行操作

int hgt = yourvalue; // both the values should be in pixels
int wdt = yourvalue; //   
Bitmap scaled = Bitmap.createScaledBitmap(largeBitmap, hgt, wdt, true);

我认为这会解决你的问题...

相关问题