android 在底部对齐,如何在Android的屏幕底部对齐addContentView
解决方案是将自定义视图包装在填充整个屏幕的RelativeLayout中,然后使用addContentView添加它.例如,要在屏幕底部添加自定义按钮:// Fake empty container layoutRelativeLayout lContainerLayout = new RelativeLayout(this);lContainerLayout.setLayoutParams(ne
解决方案是将自定义视图包装在填充整个屏幕的RelativeLayout中,然后使用addContentView添加它.例如,要在屏幕底部添加自定义按钮:
// Fake empty container layout
RelativeLayout lContainerLayout = new RelativeLayout(this);
lContainerLayout.setLayoutParams(new RelativeLayout.LayoutParams( LayoutParams.FILL_PARENT , LayoutParams.FILL_PARENT ));
// Custom view
Button mCustomView = new Button(this);
mCustomView.setText("Test");
LayoutParams lButtonParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT , LayoutParams.WRAP_CONTENT );
lButtonParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
mCustomView.setLayoutParams(lButtonParams);
lContainerLayout.addView(mCustomView);
// Adding full screen container
addContentView(lContainerLayout, new LayoutParams( LayoutParams.FILL_PARENT , LayoutParams.FILL_PARENT ) );
这应该成功
更多推荐
所有评论(0)