android - How to put a static ImageView on a screen -


i'm learning android development pretty difficult. face problem while trying put image in middle of screen. far, have 2 image buttons , text. added image on .xml file in layout when try run on device app closes. so, figure has code have no idea what's wrong.

here code. great! thanks!

public class appactivity extends activity implements ontouchlistener {      private mediaplayer mp;     imagebutton button;     imagebutton button3;     imageview image1;     imageview image;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          addlisteneronbutton();     }      public void addlisteneronbutton() {          final context context = this;         button3  = (imagebutton) this.findviewbyid(r.id.imagebutton5);         button3.setontouchlistener(this);          mp = mediaplayer.create(this, r.raw.vanilla_twilight);          image = (imageview) findviewbyid(r.id.imageview1);          button = (imagebutton) findviewbyid(r.id.imagebutton1);         button.setonclicklistener(new onclicklistener() {              @override             public void onclick(view arg0) {                  intent intent = new intent(context, app2activity.class);                             startactivity(intent);                }         });     }      @override     public boolean ontouch(view v, motionevent event) {         if (event.getaction() == motionevent.action_down) {             mediaplayer mp = mediaplayer.create(getbasecontext(),                     r.raw.vanilla_twilight);             mp.start();             mp.setoncompletionlistener(new oncompletionlistener() {                  @override                 public void oncompletion(mediaplayer mp) {                     mp.release();                 }             });         };         return true;     } } 

my xml file:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/linearlayout1"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >  <imagebutton     android:id="@+id/imagebutton5"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="right"     android:layout_marginright="30dp"     android:layout_margintop="15dp"     android:background="@drawable/ic_speak" />   <imageview     android:id="@+id/imageview1"     android:layout_width="366dp"     android:layout_height="125dp"     android:layout_gravity="center_horizontal"     android:layout_weight="0.39"     android:src="@drawable/school_bus" />  <imagebutton     android:id="@+id/imagebutton1"     android:layout_width="64dp"     android:layout_height="92dp"     android:layout_gravity="right"     android:layout_marginright="30dp"     android:layout_margintop="-155dp"     android:background="@drawable/icon" />  <textview     android:id="@+id/textview1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="center_horizontal"     android:layout_margintop="45dp"     android:text="@string/bus_pg"     android:textappearance="?android:attr/textappearancelarge"     android:textsize="50px" />  </linearlayout> 

logcat:

05-19 19:38:53.281: e/androidruntime(492): fatal exception: main 05-19 19:38:53.281: e/androidruntime(492): java.lang.runtimeexception: unable start activity componentinfo{com.example.button/com.example.button.appactivity}: android.view.inflateexception: binary xml file line #18: error inflating class <unknown> 05-19 19:38:53.281: e/androidruntime(492):  @ android.app.activitythread.performlaunchactivity(activitythread.java:2110) 05-19 19:38:53.281: e/androidruntime(492):  @ android.app.activitythread.handlelaunchactivity(activitythread.java:2135) 05-19 19:38:53.281: e/androidruntime(492):  @ android.app.activitythread.access$700(activitythread.java:143) 05-19 19:38:53.281: e/androidruntime(492):  @ android.app.activitythread$h.handlemessage(activitythread.java:1241) 05-19 19:38:53.281: e/androidruntime(492):  @ android.os.handler.dispatchmessage(handler.java:99) 05-19 19:38:53.281: e/androidruntime(492):  @ android.os.looper.loop(looper.java:137) 05-19 19:38:53.281: e/androidruntime(492):  @ android.app.activitythread.main(activitythread.java:4950) 05-19 19:38:53.281: e/androidruntime(492):  @ java.lang.reflect.method.invokenative(native method) 05-19 19:38:53.281: e/androidruntime(492):  @ java.lang.reflect.method.invoke(method.java:511) 05-19 19:38:53.281: e/androidruntime(492):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1004) 05-19 19:38:53.281: e/androidruntime(492):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:771) 05-19 19:38:53.281: e/androidruntime(492):  @ dalvik.system.nativestart.main(native method) 05-19 19:38:53.281: e/androidruntime(492): caused by: android.view.inflateexception: binary xml file line #18: error inflating class <unknown> 05-19 19:38:53.281: e/androidruntime(492):  @ android.view.layoutinflater.createview(layoutinflater.java:613) 05-19 19:38:53.281: e/androidruntime(492):  @ com.android.internal.policy.impl.phonelayoutinflater.oncreateview(phonelayoutinflater.java:56) 05-19 19:38:53.281: e/androidruntime(492):  @ android.view.layoutinflater.oncreateview(layoutinflater.java:660) 05-19 19:38:53.281: e/androidruntime(492):  @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:685) 05-19 19:38:53.281: e/androidruntime(492):  @ android.view.layoutinflater.rinflate(layoutinflater.java:746) 05-19 19:38:53.281: e/androidruntime(492):  @ android.view.layoutinflater.inflate(layoutinflater.java:489) 05-19 19:38:53.281: e/androidruntime(492):  @ android.view.layoutinflater.inflate(layoutinflater.java:396) 05-19 19:38:53.281: e/androidruntime(492):  @ android.view.layoutinflater.inflate(layoutinflater.java:352) 05-19 19:38:53.281: e/androidruntime(492):  @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:316) 05-19 19:38:53.281: e/androidruntime(492):  @ android.app.activity.setcontentview(activity.java:1915) 05-19 19:38:53.281: e/androidruntime(492):  @ com.example.button.appactivity.oncreate(appactivity.java:29) 05-19 19:38:53.281: e/androidruntime(492):  @ android.app.activity.performcreate(activity.java:5177) 05-19 19:38:53.281: e/androidruntime(492):  @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1094) 05-19 19:38:53.281: e/androidruntime(492):  @ android.app.activitythread.performlaunchactivity(activitythread.java:2074) 05-19 19:38:53.281: e/androidruntime(492):  ... 11 more 05-19 19:38:53.281: e/androidruntime(492): caused by: java.lang.reflect.invocationtargetexception 05-19 19:38:53.281: e/androidruntime(492):  @ java.lang.reflect.constructor.constructnative(native method) 05-19 19:38:53.281: e/androidruntime(492):  @ java.lang.reflect.constructor.newinstance(constructor.java:417) 05-19 19:38:53.281: e/androidruntime(492):  @ android.view.layoutinflater.createview(layoutinflater.java:587) 05-19 19:38:53.281: e/androidruntime(492):  ... 24 more 05-19 19:38:53.281: e/androidruntime(492): caused by: java.lang.outofmemoryerror 05-19 19:38:53.281: e/androidruntime(492):  @ android.graphics.bitmapfactory.nativedecodeasset(native method) 05-19 19:38:53.281: e/androidruntime(492):  @ android.graphics.bitmapfactory.decodestream(bitmapfactory.java:594) 05-19 19:38:53.281: e/androidruntime(492):  @ android.graphics.bitmapfactory.decoderesourcestream(bitmapfactory.java:447) 05-19 19:38:53.281: e/androidruntime(492):  @ android.graphics.drawable.drawable.createfromresourcestream(drawable.java:781) 05-19 19:38:53.281: e/androidruntime(492):  @ android.content.res.resources.loaddrawable(resources.java:1963) 05-19 19:38:53.281: e/androidruntime(492):  @ android.content.res.typedarray.getdrawable(typedarray.java:601) 05-19 19:38:53.281: e/androidruntime(492):  @ android.widget.imageview.<init>(imageview.java:120) 05-19 19:38:53.281: e/androidruntime(492):  @ android.widget.imageview.<init>(imageview.java:110) 05-19 19:38:53.281: e/androidruntime(492):  ... 27 more 


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -