问题很简单,我正在使用代码动态创建imageview.
ImageView btnSend = new ImageView (this);
并将其添加到LinearLayout中,问题是我想保持右对齐
怎么做?
提前致谢
解决方法:
尝试使用LayoutParams:
LinearLayout rootLayout = (LinearLayout)findViewById(R.id.root_layout);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.RIGHT;
ImageView btnSend = new ImageView (this);
btnSend.setLayoutParams(params);
rootLayout.addView(btnSend);
唯一的问题是我不记得params.gravity是否设置内容gravity或layout_gravity. Layout_gravity是您要在此实例中更改的内容.