0

我有一个新问题。

该项目需要一个带有位图的文本视图(我已将其制成 9 个补丁)作为背景,但用户可以通过手势调整其宽度和高度,就像 ms office 中的一个文本框,用户可以使用鼠标来调整文本框和其中的文字将被重新发布。

这是我的代码: 1.this是标记保存textview的属性。publicET 是一个文本视图。

                ts.setPositionX(publicET.getLeft());
                ts.setPositionY(publicET.getTop());
                ts.setLength(publicET.getBottom());
                ts.setWidth(publicET.getRight());

2.然后我显示这个textview,我设置了textview的这个属性:

                TextObject tObj = new TextObject();
                tObj.setId(Integer.parseInt(String.valueOf(id)));
                tObj.setPageId(getPageNum);
                tObj.setAlbumId(albumId);
                tObj.setContent(publicET.getText().toString());
                tObj.setPositionX(textPositionX);
                tObj.setPositionY(textPositionY);
                tObj.setLength(textPositionB);
                tObj.setWidth(textPositionR);
                tObj.setColor(curPicBackColor);
                tObj.setSize(curTextFontSize);
                tObj.setTextFont(typefacestr);
                publicET.setTag(tObj);
                publicET.setBackgroundDrawable(null);

TestObject 类是这样的:

public class TextObject {

private Integer id;
private Integer pageId;
private Integer albumId;
private String content;
private Integer positionX;
private Integer positionY;
private Integer length;
private Integer width;
private String color;
private Integer size;
private String textFont;

public Integer getId() {
    return id;
}
public void setId(Integer id) {
    this.id = id;
}
public Integer getPageId() {
    return pageId;
}
public void setPageId(Integer pageId) {
    this.pageId = pageId;
}
public Integer getAlbumId() {
    return albumId;
}
public void setAlbumId(Integer albumId) {
    this.albumId = albumId;
}
public String getContent() {
    return content;
}
public void setContent(String content) {
    this.content = content;
}
public Integer getPositionX() {
    return positionX;
}
public void setPositionX(Integer positionX) {
    this.positionX = positionX;
}
public Integer getPositionY() {
    return positionY;
}
public void setPositionY(Integer positionY) {
    this.positionY = positionY;
}
public Integer getLength() {
    return length;
}
public void setLength(Integer length) {
    this.length = length;
}
public Integer getWidth() {
    return width;
}
public void setWidth(Integer width) {
    this.width = width;
}
public String getColor() {
    return color;
}
public void setColor(String color) {
    this.color = color;
}
public Integer getSize() {
    return size;
}
public void setSize(Integer size) {
    this.size = size;
}
public String getTextFont() {
    return textFont;
}
public void setTextFont(String textFont) {
    this.textFont = textFont;
}

}

我无法控制此 textView 的属性以显示在正确的位置。我通过日志检查了位置是否正确。期待你帮助我。谢谢你。

4

1 回答 1

0

有我的代码,它可以工作:

RelativeLayout.LayoutParams paramst = new RelativeLayout.LayoutParams(
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
        paramst.setMargins(o.getPositionX(), o.getPositionY(),
                o.getWidth(), o.getLength());
        TextView e = new TextView(this);        
        e.setBackgroundResource(R.drawable.edittext_bg2);
        e.setLayoutParams(paramst);
        e.setWidth(o.getWidth()-o.getPositionX());
于 2013-11-02T10:47:13.253 回答