Android百分比布局(PercentRelativeLayout)嵌套NavigationView自定义宽度
因为NavigationView必须嵌套在DrawerLayout里,当DrawerLayout不是根布局时,就没办法用match_parent等定义宽高,会报错。所以要重写DrawerLayout的onMeasure()方法: public class MyDrawerLayout extends DrawerLayout { public MyDrawerLayout(@NonNull Context context) { super(context); } public MyDrawerLayout(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); } public MyDrawerLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { widthMeasureSpec = MeasureSpec.makeMeasureSpec(