2013-10-28 22 views
0

我有一個新問題。android使msview文本框的textview

該項目需要一個帶位圖的文本視圖(我已將它製作成9個補丁)作爲背景,但用戶可以使用手勢調整其寬度和高度,就像ms office中的文本框一樣,用戶可以使用鼠標進行重新調整文本框和文本將被重新發布。

這是我的代碼: 1.這是標記爲保存textview的屬性。 publicET是一個textview。

   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的屬性顯示在正確的位置。我通過日誌檢查了位置是正確的。 期待你的幫助。謝謝。

+0

我找到了解決辦法了。 我已經設置了textview的寬度,遵循設置佈局參數,它的工作原理就像textview.setWidth(intpx) – arjinmc

+0

請添加解決方案作爲答案並接受,所以問題將被關閉。 – sandrstar

+1

我已經提出。 – arjinmc

回答

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());