问题很简单,我正在使用代码动态创建一个图像视图。
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
设置内容重力或layout_gravity。 Layout_gravity 是您在这种情况下想要更改的内容。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)