大佬教程收集整理的这篇文章主要介绍了Android Studio 和 DrawerLayout 出现问题必须使用 MeasureSpec.EXACTLY 进行测量,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我是一名大学生,仍在学习如何使用 AndroID studio。有人可以帮我解决这个问题吗?当我进入新闻登录时它一直崩溃并向我发送此错误。它说它是 DrawerLayout,但我已经尝试了一段时间,而且我一生都找不到如何修复它。
E/AndroIDRuntime: FATAL EXCEPTION: main
Process: com.example.librolaneandroIDportal,PID: 4986
java.lang.IllegalArgumentexception: DrawerLayout must be measured with MeasureSpec.EXACTLY.
at androIDx.drawerlayout.Widget.DrawerLayout.onMeasure(DrawerLayout.java:1053)
at androID.vIEw.VIEw.measure(VIEw.java:25466)
at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:6957)
at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:194)
at androIDx.appcompat.Widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:146)
at androID.vIEw.VIEw.measure(VIEw.java:25466)
at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:6957)
at androID.Widget.linearLayout.measureChildBeforeLayout(linearLayout.java:1552)
at androID.Widget.linearLayout.measureVertical(linearLayout.java:842)
at androID.Widget.linearLayout.onMeasure(linearLayout.java:721)
at androID.vIEw.VIEw.measure(VIEw.java:25466)
at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:6957)
at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:194)
at androID.vIEw.VIEw.measure(VIEw.java:25466)
at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:6957)
at androID.Widget.linearLayout.measureChildBeforeLayout(linearLayout.java:1552)
at androID.Widget.linearLayout.measureVertical(linearLayout.java:842)
at androID.Widget.linearLayout.onMeasure(linearLayout.java:721)
at androID.vIEw.VIEw.measure(VIEw.java:25466)
at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:6957)
at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.androID.internal.policy.DecorVIEw.onMeasure(DecorVIEw.java:747)
at androID.vIEw.VIEw.measure(VIEw.java:25466)
at androID.vIEw.VIEwRootImpl.performMeasure(VIEwRootImpl.java:3397)
at androID.vIEw.VIEwRootImpl.measureHIErarchy(VIEwRootImpl.java:2228)
at androID.vIEw.VIEwRootImpl.performTraversals(VIEwRootImpl.java:2486)
at androID.vIEw.VIEwRootImpl.doTraversal(VIEwRootImpl.java:1952)
at androID.vIEw.VIEwRootImpl$TraversalRunnable.run(VIEwRootImpl.java:8171)
at androID.vIEw.Choreographer$CallBACkRecord.run(Choreographer.java:972)
at androID.vIEw.Choreographer.doCallBACks(Choreographer.java:796)
at androID.vIEw.Choreographer.doFrame(Choreographer.java:731)
at androID.vIEw.Choreographer$FramedisplayEventReceiver.run(Choreographer.java:957)
at androID.os.Handler.handleCallBACk(Handler.java:938)
at androID.os.Handler.dispatchmessage(Handler.java:99)
at androID.os.Looper.loop(Looper.java:223)
at androID.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.androID.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I/Process: Sending signal. PID: 4986 SIG: 9
这是Java文件
package com.example.librolaneandroIDportal;
import androIDx.Annotation.NonNull;
import androIDx.appcompat.app.ActionbarDrawerToggle;
import androIDx.appcompat.app.AppCompatActivity;
import androIDx.core.vIEw.GravityCompat;
import androIDx.drawerlayout.Widget.DrawerLayout;
import androID.content.Intent;
import androID.os.bundle;
import androID.vIEw.MenuItem;
import androIDx.appcompat.Widget.Toolbar;
import com.Google.androID.material.navigation.NavigationVIEw;
public class MainActivity extends AppCompatActivity implements NavigationVIEw.onNavigationItemSELEctedListener {
//Variables
DrawerLayout drawerLayout;
NavigationVIEw navigationVIEw;
Toolbar toolbar;
@OverrIDe
protected voID onCreate(Bundle savedInstanceStatE) {
super.onCreate(savedInstanceStatE);
setContentVIEw(R.layout.activity_main);
//Hooks
drawerLayout = findVIEwByID(R.ID.drawer_layout);
navigationVIEw = findVIEwByID(R.ID.nav_vIEw);
toolbar = findVIEwByID(R.ID.toolbar);
//Toolbar
setSupportActionbar(toolbar);
//Navigation Drawer Menu
navigationVIEw.bringToFront();
ActionbarDrawerToggle toggle = new ActionbarDrawerToggle(this,drawerLayout,toolbar,R.String.navigation_drawer_open,R.String.navigation_drawer_closE);
drawerLayout.addDrawerListener(togglE);
toggle.syncState();
navigationVIEw.setNavigationItemSELEctedListener(this);
navigationVIEw.setcheckedItem(R.ID.nav_homE);
}
@OverrIDe
public voID onBACkpressed() {
if(drawerLayout.isDrawerOpen(GravityCompat.START)){
drawerLayout.closeDrawer(GravityCompat.START);
}
else{
super.onBACkpressed();
}
}
@OverrIDe
public Boolean onNavigationItemSELEcted(@NonNull MenuItem menuItem) {
switch (menuItem.getItemID()) {
case R.ID.nav_home:
break;
case R.ID.nav_opac:
Intent intent = new Intent(MainActivity.this,Opac.class);
startActivity(intent);
break;
case R.ID.nav_qr:
Intent intent2 = new Intent(MainActivity.this,QRscAnner.class);
startActivity(intent2);
break;
}
drawerLayout.closeDrawer(GravityCompat.START);
return true;
}
}
这是我制作的布局。
<?xml version="1.0" enCoding="utf-8"?>
<androIDx.drawerlayout.Widget.DrawerLayout xmlns:androID="http://scheR_546_11845@as.androID.com/apk/res/androID"
xmlns:app="http://scheR_546_11845@as.androID.com/apk/res-auto"
xmlns:tools="http://scheR_546_11845@as.androID.com/tools"
androID:ID="@+ID/drawer_layout"
androID:layout_wIDth="wrap_content"
androID:layout_height="match_parent"
androID:fitsSystemwindows="true"
tools:context=".MainActivity"
tools:openDrawer="start">
<com.Google.androID.material.navigation.NavigationVIEw
androID:layout_wIDth="wrap_content"
androID:layout_height="match_parent"
androID:ID="@+ID/nav_vIEw"
app:headerLayout="@layout/header"
app:menu="@menu/main_menu"
androID:layout_gravity="start"/>
<androIDx.consTraintlayout.Widget.ConsTraintLayout
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent"
androID:BACkground="@drawable/gradIEnT_Background">
<androIDx.appcompat.Widget.Toolbar
androID:ID="@+ID/toolbar"
androID:layout_wIDth="0dp"
androID:layout_height="wrap_content"
androID:BACkground="?attr/colorPriMary"
androID:minHeight="?attr/actionbarSize"
androID:theme="?attr/actionbartheme"
app:layout_consTraintEnd_toEndOf="parent"
app:layout_consTraintStart_toStartOf="parent"
app:layout_consTrainttop_totopOf="parent"
app:navigationIcon="@drawable/ic_baseline_menu_24" />
<linearLayout
androID:ID="@+ID/linearLayout"
androID:layout_wIDth="0dp"
androID:layout_height="175dp"
androID:BACkground="@drawable/round_layouts"
androID:orIEntation="horizontal"
app:layout_consTraintBottom_totopOf="@+ID/linearLayout2"
app:layout_consTraintEnd_toEndOf="parent"
app:layout_consTraintStart_toStartOf="parent">
<androIDx.cardvIEw.Widget.CardVIEw
androID:ID="@+ID/OPACButton"
androID:layout_wIDth="0dp"
androID:layout_height="match_parent"
androID:layout_marginStart="20dp"
androID:layout_marginleft="20dp"
androID:layout_margintop="20dp"
androID:layout_marginEnd="10dp"
androID:layout_marginRight="10dp"
androID:layout_marginBottom="10dp"
androID:layout_weight="1"
androID:padding="10dp"
app:cardBACkgroundcolor="@color/ocean_green"
app:cardCornerRadius="15dp"
app:cardElevation="5dp">
<relativeLayout
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent">
<ImageVIEw
androID:ID="@+ID/opACBtnimage"
androID:layout_wIDth="38dp"
androID:layout_height="38dp"
androID:layout_marginStart="15dp"
androID:layout_marginleft="15dp"
androID:layout_margintop="15dp"
app:srcCompat="@drawable/opac_btnicon" />
<TextVIEw
androID:ID="@+ID/opACBtnlabel"
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent"
androID:layouT_Below="@ID/opACBtnimage"
androID:layout_marginStart="15dp"
androID:layout_marginleft="15dp"
androID:layout_margintop="20dp"
androID:text="@String/OPAC_btn_text"
androID:textcolor="@color/white"
androID:textSize="18sp"
app:layout_consTrainttop_toBottomOf="parent"
app:layout_consTrainttop_totopOf="parent" />
</relativeLayout>
</androIDx.cardvIEw.Widget.CardVIEw>
<androIDx.cardvIEw.Widget.CardVIEw
androID:ID="@+ID/QRbutton"
androID:layout_wIDth="0dp"
androID:layout_height="match_parent"
androID:layout_marginStart="10dp"
androID:layout_marginleft="10dp"
androID:layout_margintop="20dp"
androID:layout_marginEnd="10dp"
androID:layout_marginRight="10dp"
androID:layout_marginBottom="10dp"
androID:layout_weight="1"
androID:padding="10dp"
app:cardBACkgroundcolor="@color/ocean_green"
app:cardCornerRadius="15dp"
app:cardElevation="5dp">
<relativeLayout
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent">
<ImageVIEw
androID:ID="@+ID/qrbtnimage"
androID:layout_wIDth="38dp"
androID:layout_height="38dp"
androID:layout_marginStart="15dp"
androID:layout_marginleft="15dp"
androID:layout_margintop="15dp"
app:srcCompat="@drawable/scAnner_btnicon" />
<TextVIEw
androID:ID="@+ID/qrbtnlabel"
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent"
androID:layouT_Below="@ID/qrbtnimage"
androID:layout_marginStart="15dp"
androID:layout_marginleft="15dp"
androID:layout_margintop="20dp"
androID:text="@String/QR_btn_text"
androID:textcolor="@color/white"
androID:textSize="18sp"
app:layout_consTrainttop_toBottomOf="parent"
app:layout_consTrainttop_totopOf="parent" />
</relativeLayout>
</androIDx.cardvIEw.Widget.CardVIEw>
<androIDx.cardvIEw.Widget.CardVIEw
androID:ID="@+ID/Reservebutton"
androID:layout_wIDth="0dp"
androID:layout_height="match_parent"
androID:layout_marginStart="10dp"
androID:layout_marginleft="10dp"
androID:layout_margintop="20dp"
androID:layout_marginEnd="20dp"
androID:layout_marginRight="20dp"
androID:layout_marginBottom="10dp"
androID:layout_weight="1"
androID:padding="10dp"
app:cardBACkgroundcolor="@color/ocean_green"
app:cardCornerRadius="15dp"
app:cardElevation="5dp">
<relativeLayout
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent">
<ImageVIEw
androID:ID="@+ID/reservebtnimage"
androID:layout_wIDth="38dp"
androID:layout_height="38dp"
androID:layout_marginStart="15dp"
androID:layout_marginleft="15dp"
androID:layout_margintop="15dp"
app:srcCompat="@drawable/opac_btnicon" />
<TextVIEw
androID:ID="@+ID/reservebtnlabel"
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent"
androID:layouT_Below="@ID/reservebtnimage"
androID:layout_marginStart="15dp"
androID:layout_marginleft="15dp"
androID:layout_margintop="20dp"
androID:text="@String/Reserve_btn_text"
androID:textcolor="@color/white"
androID:textSize="18sp"
app:layout_consTrainttop_toBottomOf="parent"
app:layout_consTrainttop_totopOf="parent" />
</relativeLayout>
</androIDx.cardvIEw.Widget.CardVIEw>
</linearLayout>
<linearLayout
androID:ID="@+ID/linearLayout2"
androID:layout_wIDth="0dp"
androID:layout_height="175dp"
androID:BACkground="@color/white"
androID:orIEntation="horizontal"
app:layout_consTraintBottom_toBottomOf="parent"
app:layout_consTraintEnd_toEndOf="parent"
app:layout_consTraintHorizontal_bias="1.0"
app:layout_consTraintStart_toStartOf="parent">
<androIDx.cardvIEw.Widget.CardVIEw
androID:ID="@+ID/Favoritesbutton"
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent"
androID:layout_marginStart="20dp"
androID:layout_marginleft="20dp"
androID:layout_margintop="10dp"
androID:layout_marginEnd="10dp"
androID:layout_marginRight="10dp"
androID:layout_marginBottom="20dp"
androID:layout_weight="1"
androID:padding="10dp"
app:cardBACkgroundcolor="@color/ocean_green"
app:cardCornerRadius="15dp"
app:cardElevation="5dp">
<relativeLayout
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent">
<ImageVIEw
androID:ID="@+ID/favoritesbtnimage"
androID:layout_wIDth="38dp"
androID:layout_height="38dp"
androID:layout_marginStart="15dp"
androID:layout_marginleft="15dp"
androID:layout_margintop="15dp"
app:srcCompat="@drawable/opac_btnicon" />
<TextVIEw
androID:ID="@+ID/favoritesbtnlabel"
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent"
androID:layouT_Below="@ID/favoritesbtnimage"
androID:layout_marginStart="15dp"
androID:layout_marginleft="15dp"
androID:layout_margintop="20dp"
androID:text="@String/Favorite_btn_text"
androID:textcolor="@color/white"
androID:textSize="18sp"
app:layout_consTrainttop_toBottomOf="parent"
app:layout_consTrainttop_totopOf="parent" />
</relativeLayout>
</androIDx.cardvIEw.Widget.CardVIEw>
<androIDx.cardvIEw.Widget.CardVIEw
androID:ID="@+ID/Notificationbutton"
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent"
androID:layout_marginStart="10dp"
androID:layout_marginleft="10dp"
androID:layout_margintop="10dp"
androID:layout_marginEnd="10dp"
androID:layout_marginRight="10dp"
androID:layout_marginBottom="20dp"
androID:layout_weight="1"
androID:padding="10dp"
app:cardBACkgroundcolor="@color/ocean_green"
app:cardCornerRadius="15dp"
app:cardElevation="5dp">
<relativeLayout
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent">
<ImageVIEw
androID:ID="@+ID/notificationbtnimage"
androID:layout_wIDth="38dp"
androID:layout_height="38dp"
androID:layout_marginStart="15dp"
androID:layout_marginleft="15dp"
androID:layout_margintop="15dp"
app:srcCompat="@drawable/opac_btnicon" />
<TextVIEw
androID:ID="@+ID/notificationbtnlabel"
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent"
androID:layouT_Below="@ID/notificationbtnimage"
androID:layout_marginStart="15dp"
androID:layout_marginleft="15dp"
androID:layout_margintop="20dp"
androID:text="@String/Notifications_btn_text"
androID:textcolor="@color/white"
androID:textSize="18sp"
app:layout_consTrainttop_toBottomOf="parent"
app:layout_consTrainttop_totopOf="parent" />
</relativeLayout>
</androIDx.cardvIEw.Widget.CardVIEw>
<androIDx.cardvIEw.Widget.CardVIEw
androID:ID="@+ID/FeedBACkbutton"
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent"
androID:layout_marginStart="10dp"
androID:layout_marginleft="10dp"
androID:layout_margintop="10dp"
androID:layout_marginEnd="20dp"
androID:layout_marginRight="20dp"
androID:layout_marginBottom="20dp"
androID:layout_weight="1"
androID:padding="10dp"
app:cardBACkgroundcolor="@color/ocean_green"
app:cardCornerRadius="15dp"
app:cardElevation="5dp">
<relativeLayout
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent">
<ImageVIEw
androID:ID="@+ID/FeedBACkbtnimage"
androID:layout_wIDth="38dp"
androID:layout_height="38dp"
androID:layout_marginStart="15dp"
androID:layout_marginleft="15dp"
androID:layout_margintop="15dp"
app:srcCompat="@drawable/opac_btnicon" />
<TextVIEw
androID:ID="@+ID/FeedBACkbtnlabel"
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent"
androID:layouT_Below="@ID/FeedBACkbtnimage"
androID:layout_marginStart="15dp"
androID:layout_marginleft="15dp"
androID:layout_margintop="20dp"
androID:text="@String/FeedBACk_btn_text"
androID:textcolor="@color/white"
androID:textSize="18sp"
app:layout_consTrainttop_toBottomOf="parent"
app:layout_consTrainttop_totopOf="parent" />
</relativeLayout>
</androIDx.cardvIEw.Widget.CardVIEw>
</linearLayout>
</androIDx.consTraintlayout.Widget.ConsTraintLayout>
</androIDx.drawerlayout.Widget.DrawerLayout>
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的Android Studio 和 DrawerLayout 出现问题必须使用 MeasureSpec.EXACTLY 进行测量全部内容,希望文章能够帮你解决Android Studio 和 DrawerLayout 出现问题必须使用 MeasureSpec.EXACTLY 进行测量所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。