【问题标题】:RelativeLayout addView LEFT_TO Center View,Then the Center View doesn`t still in the center,why?RelativeLayout addView LEFT_TO 中心视图,那么中心视图不在中心,为什么?
【发布时间】:2015-11-27 06:55:22
【问题描述】:

如题,下图

代码:

textView = new TextView(mContext);
textView.setId(5005);
textView.setText(mShareText);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mShareTextSize);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.alignWithParent = true;
params.addRule(CENTER_IN_PARENT, TRUE);
addView(textView, params);

imageView = new ImageView(mContext);
initImageView();
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params2.addRule(LEFT_OF, 5005);
params2.addRule(CENTER_VERTICAL, TRUE);
params2.rightMargin = mDrawablePaddingDP;
addView(imageView, params2);

setControlAble();

这是扩展 RelativeLayout 的自定义视图。 我要M还在中间,程序留给M,怎么办?

【问题讨论】:

  • 它只在中心出现,我用你的代码试过了。

标签: android android-layout android-relativelayout android-custom-view


【解决方案1】:

再创建一个文本视图,给它一个 ID 并将文本设置为“”(空格或空白)。现在设置在中间。现在您可以将图像和文本视图设置为左侧。祝您好运。

【讨论】:

    猜你喜欢
    • 2015-02-23
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多