对齐的ImageView中的LinearLayout由code [英] Align Imageview in LinearLayout by code

查看:160
本文介绍了对齐的ImageView中的LinearLayout由code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题很简单,我是动态创建的ImageView使用code。

the question is simple, i am creating a imageview dynamically using code.

ImageView btnSend = new ImageView (this);

和它添加到的LinearLayout,问题是,我要离开右对齐

and add it to a LinearLayout, the problem is that I want to leave right-aligned

该怎么做?

在此先感谢

推荐答案

请尝试使用的LayoutParams:

Try using 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就是你想在这种情况下更改。

The only problem is that I don't remember if params.gravity sets the content gravity or layout_gravity. Layout_gravity is what you're wanting to change in this instance.

这篇关于对齐的ImageView中的LinearLayout由code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆