有问题的代码
RelativeLayout layout;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);layout = findViewById( R.id.content);layout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT ,RelativeLayout.LayoutParams.WRAP_CONTENT));}
有问题的是:关键部分是,高度设置为自适应导致的,由于代码设置自适应导致布局,有时候中间代码动态设置宽高,跟xml布局宽高冲突之后导致部分高度设置有误
解决方法: 把宽度、高度自适应都换成 LayoutParams.MATCH_PARENT
RelativeLayout layout;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);layout = findViewById( R.id.content);layout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT ,RelativeLayout.LayoutParams.MATCH_PARENT));}