使用imageview在android中显示图像

时间:2016-02-19 21:19:31

标签: java android

我一直在尝试在imageview中显示png图像( ic_menu_pic.png ),但是当我尝试运行我的结果时 - (很遗憾,Testapp已停止即可。)

这是我的 Main.java 文件

package com.myfile.isaac.testapp;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         ImageView imageView =(ImageView)findViewById(R.id.imageView2);
    }
     public void onSend (View view){
        Intent intent = new Intent(this, Activity2.class);
       startActivity(intent);
    }
}

以下是 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/re/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="com.myapp.isaac.testapp.MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/OKAY"
        android:id="@+id/button"
        android:onClick="onSend"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="@string/We_help_you_find_your_desired_House"
        android:id="@+id/textView2"
        android:layout_above="@+id/button"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="45dp"
        android:textAlignment="center" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView2"
        android:src="@drawable/ic_menu_pic"
        android:layout_alignRight="@+id/textView2"
        android:layout_alignEnd="@+id/textView2"
        android:layout_above="@+id/textView2"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true" />

</RelativeLayout>

这是我的日志猫,但它似乎没有结束

02-20 09:54:52.384 561-671/? W/System.err:     at libcore.net.url.FtpURLConnection.connect(FtpURLConnection.java:210) 02-20 09:54:52.385 561-671/? W/System.err:     at com.mediatek.epo.MtkEpoClientManagerService.ftpDownload(MtkEpoClientManagerService.java:223) 02-20 09:54:52.385 561-671/? W/System.err:     at com.mediatek.epo.MtkEpoClientManagerService.epoDownload(MtkEpoClientManagerService.java:459) 02-20 09:54:52.386 561-671/? W/System.err:     at com.mediatek.epo.MtkEpoClientManagerService.startEpoDownload(MtkEpoClientManagerService.java:504) 02-20 09:54:52.386 561-671/? W/System.err:     at com.mediatek.epo.MtkEpoClientManagerService.access$400(MtkEpoClientManagerService.java:67) 02-20 09:54:52.386 561-671/? W/System.err:     at com.mediatek.epo.MtkEpoClientManagerService$2$1.handleMessage(MtkEpoClientManagerService.java:449) 02-20 09:54:52.386 561-671/? W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:107) 02-20 09:54:52.387 561-671/? W/System.err:     at android.os.Looper.loop(Looper.java:194) 02-20 09:54:52.387 561-671/? W/System.err:     at com.mediatek.epo.MtkEpoClientManagerService$2.run(MtkEpoClientManagerService.java:453) 02-20 09:54:52.388 561-671/? D/[MtkEpoClientManagerService]: WARNING: retry download=4 02-20 09:54:52.388 561-671/? D/[MtkEpoClientManagerService]: download ret=false mManualStop=false 02-20 09:54:52.389 561-671/? D/[MtkEpoClientManagerService]: set timer 1296000 sec 02-20 09:54:52.389 561-671/? V/AlarmManager: set: Alarm{41c90868 type 0 android} 02-20 09:54:52.390 561-671/? V/AlarmManager: Adding alarm Alarm{41c90868 type 0 android} at 10 02-20 09:54:52.390 561-671/? D/[MtkEpoClientManagerService]: startEpoDownload --

   02-20 09:54:52.392 17612-17612/? D/Settings/QuickGpsService: epo update failure 
    02-20 09:54:52.392 17612-17612/? D/Settings/QuickGpsService: HandleEpoDownloadFail 
    02-20 09:54:52.393 561-576/? V/AlarmManager: set: Alarm{41c6c430 type 2 com.android.settings}
    02-20 09:54:52.394 561-576/? V/AlarmManager: Adding alarm Alarm{41c6c430 type 2 com.android.settings} at 3
    02-20 09:54:52.394 17612-17612/? D/Settings/QuickGpsService: epo is idle 
    02-20 09:54:56.170 30336-30336/? E/MCA: [logswitch]:mtklogger_file open success!
    02-20 09:54:56.170 30336-30336/? E/MCA: Here call up the service!
    02-20 09:54:56.170 173-173/? D/ADB_SERVICES: adb fdevent_process list (18) (11) 
    02-20 09:54:56.171 30336-30336/? E/MCA: LT passed!
    02-20 09:55:00.000 561-598/? V/AlarmManager: Checking for alarms... rtc=1455951300000, elapsed=834239386
    02-20 09:55:00.000 561-598/? V/AlarmManager: Checking active alarm when=834239386 Alarm{41b1e778 type 2 com.whatsapp}
    02-20 09:55:00.001 561-598/? V/AlarmManager: Alarm triggering: Alarm{41b1e778 type 2 com.whatsapp}
    02-20 09:55:00.001 561-598/? V/AlarmManager: Checking active alarm when=834260087 Alarm{41a10b50 type 2 com.whatsapp}
    02-20 09:55:00.002 561-598/? V/AlarmManager: Adding alarm Alarm{41b1e778 type 2 com.whatsapp} at 7
    02-20 09:55:00.002 561-598/? V/AlarmManager: Native set alarm :Alarm{41a10b50 type 2 com.whatsapp}
    02-20 09:55:00.003 561-598/? V/AlarmManager: Checking active alarm when=834239386 Alarm{41c67de8 type 3 android}
    02-20 09:55:00.003 561-598/? V/AlarmManager: Alarm triggering: Alarm{41c67de8 type 3 android}
    02-20 09:55:00.003 561-598/? V/AlarmManager: Checking active alarm when=834300000 Alarm{41872f48 type 3 android}
    02-20 09:55:00.004 561-598/? V/AlarmManager: Native set alarm :Alarm{41872f48 type 3 android}
    02-20 09:55:00.004 561-598/? I/AlarmManager: mBootPackage = com.android.deskclock set Prop 1
    02-20 09:55:00.028 561-598/? I/AlarmManager: rest power off alarm is com.android.deskclock
    02-20 09:55:00.029 561-598/? D/Provider/Settings: put string name = power_off_alarm_package_name , value = com.android.deskclock userHandle = 0
    02-20 09:55:00.029 561-598/? D/SettingsProvider: call request for 0
    02-20 09:55:00.029 561-598/? V/SettingsProvider: call_put(system:power_off_alarm_package_name=com.android.deskclock) for 0
    02-20 09:55:00.029 561-598/? V/SettingsProvider: insert(content://settings/system) for user 0 by 0
    02-20 09:55:00.030 561-598/? D/SettingsProvider: insert(content://settings/system) for user 0 by 0
    02-20 09:55:00.030 561-598/? D/SettingsProvider: redundant, old Value: com.android.deskclock new value: com.android.deskclock
    02-20 09:55:00.030 561-598/? V/AlarmManager: sending alarm Alarm{41b1e778 type 2 com.whatsapp}
    02-20 09:55:00.031 561-598/? V/ActivityManager: Broadcast: Intent { act=com.whatsapp.messaging.MessageService.CLIENT_PINGER_ACTION flg=0x14 (has extras) } ordered=true userid=0 callerApp=null
    02-20 09:55:00.037 561-598/? D/PowerManagerService: acquireWakeLockInternal: lock=1096359152, flags=0x1, tag="AlarmManager", ws={WorkSource: uids=[10082]}, uid=1000, pid=561
    02-20 09:55:00.038 561-598/? D/PowerManagerService: updateWakeLockSummaryLocked: mWakefulness=Asleep, mWakeLockSummary=0x1
    02-20 09:55:00.039 561-598/? D/PowerManagerService: newScreenState = 0 02-20 09:55:00.039 561-598/? D/PowerManagerDisplayController: requestPowerState: screenState=0, useProximitySensor=false, screenBrightness=108, screenAutoBrightnessAdjustment=0.0, useAutoBrightness=false, useEcoBrightness=false, blockScreenOn=false, waitForNegativeProximity=false
    02-20 09:55:00.039 561-598/? I/PowerManagerService: setBrightness mButtonLight 0.
    02-20 09:55:00.040 561-598/? D/PowerManagerService: updateScreenStateLocked: mDisplayReady=true, newScreenState=0, mWakefulness=0, mWakeLockSummary=0x1, mUserActivitySummary=0x0, mBootCompleted=true
    02-20 09:55:00.040 561-598/? D/PowerManagerService: updateSuspendBlockerLocked: Acquiring suspend blocker.
    02-20 09:55:00.041 561-598/? I/AlarmManager: mBootPackage = com.android.deskclock set Prop 1
    02-20 09:55:00.079 561-598/? I/AlarmManager: rest power off alarm is com.android.deskclock    02-20 09:55:00.080 561-598/? D/Provider/Settings: put string name = power_off_alarm_package_name , value = com.android.deskclock userHandle = 0
    02-20 09:55:00.080 561-598/? D/SettingsProvider: call request for 0    02-20 09:55:00.080 561-598/? V/SettingsProvider: call_put(system:power_off_alarm_package_name=com.android.deskclock) for 0    02-20 09:55:00.081 561-598/? V/SettingsProvider: insert(content://settings/system) for user 0 by 0
    02-20 09:55:00.081 561-598/? D/SettingsProvider: insert(content://settings/system) for user 0 by 0
    02-20 09:55:00.081 561-598/? D/SettingsProvider: redundant, old Value: com.android.deskclock new value: com.android.deskclock
    02-20 09:55:00.082 561-598/? V/AlarmManager: sending alarm Alarm{41c67de8 type 3 android}
    02-20 09:55:00.082 561-598/? V/ActivityManager: Broadcast: Intent { act=android.intent.action.TIME_TICK flg=0x40000014 (has extras) } ordered=true userid=-1 callerApp=null
    02-20 09:55:00.086 561-577/? D/ActivityThread: BDC-Calling onReceive: intent=Intent { act=android.intent.action.TIME_TICK flg=0x40000014 (has extras) }, ordered=true, receiver=com.android.server.AlarmManagerService$ClockReceiver@416ee530, IIntentReceiver=41850c98
    02-20 09:55:00.086 561-561/? V/AlarmManager: set: Alarm{41b6e0d8 type 2 com.whatsapp}
    02-20 09:55:00.086 561-561/? V/AlarmManager: Adding alarm Alarm{41b6e0d8 type 2 com.whatsapp} at 1
    02-20 09:55:00.087 561-577/? V/AlarmManager: set: Alarm{41b563b8 type 3 android}
    02-20 09:55:00.087 561-577/? V/AlarmManager: Adding alarm Alarm{41b563b8 type 3 android} at 0
    02-20 09:55:00.087 561-577/? V/AlarmManager: Native set alarm :Alarm{41b563b8 type 3 android}
    02-20 09:55:00.087 561-577/? D/ActivityThread: BDC-Calling finishReceiver: IIntentReceiver=41850c98
    02-20 09:55:00.090 561-577/? D/ActivityThread: BDC-Calling onReceive: intent=Intent { act=android.intent.action.TIME_TICK flg=0x40000014 (has extras) }, ordered=true, receiver=com.android.internal.policy.impl.keyguard.KeyguardUpdateMonitor$2@418dc1a8, IIntentReceiver=41906910
     02-20 09:55:00.090 561-596/? D/PowerManagerService: handleSandman: canDream=false, mWakefulness=Asleep
    02-20 09:55:00.090 561-577/? D/KeyguardUpdateMonitor: received broadcast android.intent.action.TIME_TICK 02-20 09:55:00.091 561-579/? D/KeyguardUpdateMonitor: handleTimeUpdate
    02-20 09:55:00.092 561-579/? V/Provider/Settings:  from settings cache , name = time_12_24 , value = null
    02-20 09:55:00.093 561-579/? V/Provider/Settings:  from settings cache , name = time_12_24 , value = null
    02-20 09:55:00.096 561-577/? D/ActivityThread: BDC-Calling finishReceiver: IIntentReceiver=41906910
    02-20 09:55:00.099 695-695/? D/Clock: SystemUI onReceive intent action = android.intent.action.TIME_TICK
    02-20 09:55:00.099 695-695/? D/Clock: SystemUI updateClock currentTimeMillis = 1455951300099
    02-20 09:55:00.099 695-695/? D/Clock: SystemUI AM_PM_STYLE = 1
    02-20 09:55:00.099 695-695/? V/Provider/Settings:  from settings cache , name = time_12_24 , value = null
    02-20 09:55:00.100 695-695/? D/Clock: SystemUI updateClock b24 = false
    02-20 09:55:00.101 695-695/? D/Clock: SystemUI formatted = 9:55 AM
    02-20 09:55:00.105 695-695/? D/Clock: SystemUI onReceive intent action = android.intent.action.TIME_TICK
    02-20 09:55:00.105 695-695/? D/Clock: SystemUI updateClock currentTimeMillis = 1455951300105
    02-20 09:55:00.105 695-695/? D/Clock: SystemUI AM_PM_STYLE = 1
    02-20 09:55:00.105 695-695/? V/Provider/Settings:  from settings cache , name = time_12_24 , value = null
    02-20 09:55:00.105 695-695/? D/Clock: SystemUI updateClock b24 = false
    02-20 09:55:00.106 695-695/? D/Clock: SystemUI formatted = 9:55 AM
    02-20 09:55:00.111 695-695/? D/Clock: SystemUI onReceive intent action = android.intent.action.TIME_TICK
    02-20 09:55:00.111 695-695/? D/Clock: SystemUI updateClock currentTimeMillis = 1455951300111
    02-20 09:55:00.111 695-695/? D/Clock: SystemUI AM_PM_STYLE = 1
    02-20 09:55:00.111 695-695/? V/Provider/Settings:  from settings cache , name = time_12_24 , value = null
    02-20 09:55:00.118 695-695/? D/Clock: SystemUI updateClock b24 = false
    02-20 09:55:00.119 695-695/? D/Clock: SystemUI formatted = 9:55 AM
    02-20 09:55:00.132 561-577/? D/ActivityThread: BDC-Calling onReceive: intent=Intent { act=android.intent.action.TIME_TICK flg=0x40000014 (has extras) }, ordered=true, receiver=com.android.internal.policy.impl.keyguard.ClockView$TimeChangedReceiver@41a588c0, IIntentReceiver=41a58580
    02-20 09:55:00.132 561-577/? D/ActivityThread: BDC-Calling finishReceiver: IIntentReceiver=41a58580
    02-20 09:55:00.134 561-577/? D/PowerManagerService: releaseWakeLockInternal: lock=1096359152, flags=0x0
    02-20 09:55:00.135 561-577/? D/PowerManagerService: updateWakeLockSummaryLocked: mWakefulness=Asleep, mWakeLockSummary=0x0
    02-20 09:55:00.135 561-577/? D/PowerManagerService: newScreenState = 0
    02-20 09:55:00.135 561-577/? D/PowerManagerDisplayController: requestPowerState: screenState=0, useProximitySensor=false, screenBrightness=108, screenAutoBrightnessAdjustment=0.0, useAutoBrightness=false, useEcoBrightness=false, blockScreenOn=false, waitForNegativeProximity=false
    02-20 09:55:00.136 561-577/? I/PowerManagerService: setBrightness mButtonLight 0.
    02-20 09:55:00.136 561-577/? D/PowerManagerService: updateScreenStateLocked: mDisplayReady=true, newScreenState=0, mWakefulness=0, mWakeLockSummary=0x0, mUserActivitySummary=0x0, mBootCompleted=true
    02-20 09:55:00.136 561-577/? D/PowerManagerService: updateSuspendBlockerLocked: Releasing suspend blocker.
    02-20 09:55:00.142 929-1174/? D/PacketsControl: wifi connected. do nothing.
    02-20 09:55:00.151 561-579/? V/Provider/Settings:  from settings cache , name = time_12_24 , value = null
    02-20 09:55:00.153 561-579/? V/Provider/Settings:  from settings cache , name = time_12_24 , value = null
    02-20 09:55:00.185 561-596/? D/PowerManagerService: handleSandman: canDream=false, mWakefulness=Asleep
    02-20 09:55:00.449 151-151/? D/battery_warning: systemServerStarted: ps -t | grep ActivityManager 
    02-20 09:55:00.574 151-151/? D/battery_warning: cmd result: system    581   561   501164 55640 ffffffff 00000000 S ActivityManager
    02-20 09:55:01.085 30340-30340/? E/MCA: [logswitch]:mtklogger_file open success!
    02-20 09:55:01.086 30340-30340/? E/MCA: Here call up the service!
    02-20 09:55:01.086 30340-30340/? E/MCA: LT passed!
    02-20 09:55:06.097 30341-30341/? E/MCA: [logswitch]:mtklogger_file open success!
    02-20 09:55:06.098 30341-30341/? E/MCA: Here call up the service!
    02-20 09:55:06.098 173-173/? D/ADB_SERVICES: adb fdevent_process list (18) (11) 
    02-20 09:55:06.098 30341-30341/? E/MCA: LT passed!
    02-20 09:55:10.575 151-151/? D/battery_warning: systemServerStarted: ps -t | grep ActivityManager 
    02-20 09:55:10.705 151-151/? D/battery_warning: cmd result: system    581   561   501164 55640 ffffffff 00000000 S ActivityManager
    02-20 09:55:11.110 30345-30345/? E/MCA: [logswitch]:mtklogger_file open success!
    02-20 09:55:11.110 30345-30345/? E/MCA: Here call up the service!
    02-20 09:55:11.110 173-173/? D/ADB_SERVICES: adb fdevent_process list (18) (11) 
    02-20 09:55:11.110 30345-30345/? E/MCA: LT passed!
    02-20 09:55:11.560 561-577/? V/Provider/Settings:  from settings cache , name = sys_free_storage_log_interval , value = null
    02-20 09:55:11.560 561-577/? V/Provider/Settings:  from settings cache , name = disk_free_change_reporting_threshold , value = null

1 个答案:

答案 0 :(得分:0)

我用其他一些.png图像尝试了你的代码,它的确有效! 您可以尝试将图像更改一次。 请看下面的内容。

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="developer.bd.com.demo.MainActivity"
    tools:showIn="@layout/activity_main">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="okay"
        android:id="@+id/button"
        android:onClick="onSend"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="We_help_you_find_your_desired_House"
        android:id="@+id/textView2"
        android:layout_above="@+id/button"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="45dp"
        android:textAlignment="center" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView2"
        android:src="@drawable/android"
        android:layout_alignRight="@+id/textView2"
        android:layout_alignEnd="@+id/textView2"
        android:layout_above="@+id/textView2"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true" />


</RelativeLayout>