android - Error with DrawerLayout -
when try open activity gridview , drawerlayout, have error:
04-14 16:16:44.203 2226-2226/? e/androidruntime﹕ fatal exception: main process: com.example.proyectotaes.proyecto1, pid: 2226 java.lang.illegalargumentexception: drawerlayout must measured measurespec.exactly. @ android.support.v4.widget.drawerlayout.onmeasure(drawerlayout.java:814) @ android.view.view.measure(view.java:17430) @ android.widget.gridview.onmeasure(gridview.java:1074) @ android.view.view.measure(view.java:17430) @ android.widget.relativelayout.measurechildhorizontal(relativelayout.java:727) @ android.widget.relativelayout.onmeasure(relativelayout.java:463) @ android.view.view.measure(view.java:17430) @ android.support.v4.widget.drawerlayout.onmeasure(drawerlayout.java:851) @ android.view.view.measure(view.java:17430) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5463) @ android.widget.framelayout.onmeasure(framelayout.java:430) @ android.view.view.measure(view.java:17430) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5463) @ android.support.v7.internal.widget.actionbaroverlaylayout.onmeasure(actionbaroverlaylayout.java:453) @ android.view.view.measure(view.java:17430) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5463) @ android.widget.framelayout.onmeasure(framelayout.java:430) @ android.view.view.measure(view.java:17430) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5463) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1436) @ android.widget.linearlayout.measurevertical(linearlayout.java:722) @ android.widget.linearlayout.onmeasure(linearlayout.java:613) @ android.view.view.measure(view.java:17430) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5463) @ android.widget.framelayout.onmeasure(framelayout.java:430) @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2560) @ android.view.view.measure(view.java:17430) @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:2001) @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1166) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1372) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1054) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5779) @ android.view.choreographer$callbackrecord.run(choreographer.java:767) @ android.view.choreographer.docallbacks(choreographer.java:580) @ android.view.choreographer.doframe(choreographer.java:550) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:753) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5221) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:694)
this code of activity:
xml:
<android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context="com.example.proyectotaes.proyecto1.usuarios"> <gridview android:id="@+id/gridview" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:choicemode="singlechoice" android:divider="@android:color/transparent" android:dividerheight="0dp" /> <framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.example.proyectotaes.proyecto1.squareimageview android:id="@+id/picture" android:layout_width="match_parent" android:layout_height="match_parent" android:scaletype="centercrop" /> <textview android:id="@+id/text" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingleft="10dp" android:paddingright="10dp" android:paddingtop="15dp" android:paddingbottom="10dp" android:textcolor="@android:color/white" android:layout_gravity="bottom" android:background="#55000000" /> </framelayout> </relativelayout> <listview android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:choicemode="singlechoice" android:divider="@android:color/transparent" android:dividerheight="0dp" android:background="#111"/> </android.support.v4.widget.drawerlayout>
activity:
public class usuarios extends actionbaractivity { private arraylist<string> datos; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_usuarios); //caso de prueba, luego sera la consulta la base de datos datos = new arraylist<string>(); datos.add("dario"); datos.add("marcelito"); datos.add("sagal"); datos.add("miguel"); datos.add("antonio"); datos.add("agustin"); gridview grid = (gridview) findviewbyid(r.id.gridview); //se pasan los datos recogidos de la base de datos grid.setadapter(new myadapter(this, datos)); }
myadapter:
public class myadapter extends baseadapter { private list items = new arraylist(); private layoutinflater inflater; public myadapter(context context, arraylist<string> datos) { inflater = layoutinflater.from(context); //se cargan todos los nombres "datos" for(int = 0 ; i<datos.size(); i++) { items.add(new item(datos.get(i), r.drawable.colores)); } } @override public int getcount() { return items.size(); } @override public object getitem(int i) { return items.get(i); } @override public long getitemid(int i) { //return items.get(i).drawableid; return 4; } @override public view getview(int i, view view, viewgroup viewgroup) { view v = view; imageview picture; textview name; if(v == null) { v = inflater.inflate(r.layout.activity_usuarios, viewgroup, false); v.settag(r.id.picture, v.findviewbyid(r.id.picture)); v.settag(r.id.text, v.findviewbyid(r.id.text)); } picture = (imageview)v.gettag(r.id.picture); name = (textview)v.gettag(r.id.text); item item = (item)getitem(i); picture.setimageresource(item.drawableid); name.settext(item.name); return v; } private class item { final string name; final int drawableid; item(string name, int drawableid) { this.name = name; this.drawableid = drawableid; } } }
you inflating r.layout.activity_usuarios
each row in myadapter
rather layout specific gridview
.
this causes each row have drawerlayout
, gridview
, , listview
inside of not want.
Comments
Post a Comment