다음은 question에 따라 이미지 주위에 텍스트를 넣을 수있었습니다. 그러나, 나는 다음과 같은 문제가 있습니다. 이미지 주위의 Android 텍스트 버그
당신이 볼 수 있듯이
은 상단에 이미지의 공간은 오른쪽에있는 모든 단락에 표시됩니다. 질문에 누군가가이 문제가 있었고 '줄'에 대해 'ss.length()'를 변경하도록 제안했습니다. 이것은 첫 단락이 너무 짧다면 다음 단락이 이미지와 겹칠 경우를 제외하고는 효과가있는 것으로 보입니다.Html의 텍스트를 사용하기 위해 FlowTextHelper 클래스를 약간 수정했습니다. 이것은 내가 사용하고있는 코드입니다 :
public class FlowTextHelper {
private static boolean mNewClassAvailable;
/* class initialization fails when this throws an exception */
static {
try {
Class.forName("android.text.style.LeadingMarginSpan$LeadingMarginSpan2");
mNewClassAvailable = true;
} catch (Exception ex) {
mNewClassAvailable = false;
}
}
public static void tryFlowText(String text, View thumbnailView, TextView messageView, Display display, int addPadding){
// There is nothing I can do for older versions, so just return
if(!mNewClassAvailable) return;
// Get height and width of the image and height of the text line
thumbnailView.measure(display.getWidth(), display.getHeight());
int height = thumbnailView.getMeasuredHeight();
int width = thumbnailView.getMeasuredWidth() + addPadding;
messageView.measure(width, height); //to allow getTotalPaddingTop
int padding = messageView.getTotalPaddingTop();
float textLineHeight = messageView.getPaint().getTextSize();
// Set the span according to the number of lines and width of the image
int lines = (int)Math.round((height - padding)/textLineHeight);
//SpannableString ss = new SpannableString(text);
//For an html text you can use this line:
if(!text.equals("")) {
SpannableStringBuilder ss = (SpannableStringBuilder) Html.fromHtml(text);
ss.setSpan(new MyLeadingMarginSpan2(lines, width), 0, ss.length(), 0);
messageView.setText(ss);
messageView.setMovementMethod(LinkMovementMethod.getInstance()); // links
// Align the text with the image by removing the rule that the text is to the right of the image
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) messageView.getLayoutParams();
int[] rules = params.getRules();
rules[RelativeLayout.RIGHT_OF] = 0;
}
}
}
public class MyLeadingMarginSpan2 implements LeadingMarginSpan.LeadingMarginSpan2 {
private int margin;
private int lines;
public MyLeadingMarginSpan2(int lines, int margin) {
this.margin = margin;
this.lines = lines;
}
@Override
public int getLeadingMargin(boolean first) {
return first ? margin : 0;
}
@Override
public int getLeadingMarginLineCount() {
return lines;
}
@Override
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir,
int top, int baseline, int bottom, CharSequence text,
int start, int end, boolean first, Layout layout) {}
}
모든 단락이 반복되는 이유는 무엇이며 어떻게 제거 할 수 있습니까? 어떤 도움을 주셔서 감사합니다.
이 문제가 발생하는 이유가 궁금한 분은 https://code.google.com/p/에있는 버그입니다. android/issues/detail? id = 38003 – Parker