Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 动态文本视图,尽可能填充空间_Android_Android Layout_Textview_Android View - Fatal编程技术网

Android 动态文本视图,尽可能填充空间

Android 动态文本视图,尽可能填充空间,android,android-layout,textview,android-view,Android,Android Layout,Textview,Android View,在安卓系统中,我们有一些限制,所以我们可以将视图放在另一个视图的开始和结束位置 特别是TextView当您将它的结束设置为另一个视图的开始时,它将如下所示:- Tex | Another View tVi | ew | Tex | Another View tView | Parent device border 是否有任何布局可以帮助我获得动态TextView,例如,上面的布局看起来像:- Tex | Another View tVi | ew | Tex | Another Vie

在安卓系统中,我们有一些限制,所以我们可以将视图放在另一个视图的开始和结束位置

特别是
TextView
当您将它的结束设置为另一个视图的开始时,它将如下所示:-

Tex | Another View
tVi |
ew  |
Tex | Another View
tView | Parent device border
是否有任何布局可以帮助我获得动态
TextView
,例如,上面的布局看起来像:-

Tex | Another View
tVi |
ew  |
Tex | Another View
tView | Parent device border
以下是一个可视示例:-

也许可以解决你的问题。FlowTextView基于RelativeLayout,添加了文本视图功能,将文本环绕在其子项周围

或者,如果文本视图位于右侧,图像位于左侧,您可以这样做:

---------
| Image | Text that is so
--------- long that it's 
 wrapping around the image
public class MyLeadingMarginSpan2 implements LeadingMarginSpan.LeadingMarginSpan2 {

int lines;
int offset;

public MyLeadingMarginSpan2(int lines, int offset) {
    this.lines = lines;
    this.offset = offset;
}

@Override
public int getLeadingMarginLineCount() {
    return lines;
}

@Override
public int getLeadingMargin(boolean first) {
    return first ? offset : 0;
}

@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) {

    }
}
您可以尝试以下方法:

这样实施:

---------
| Image | Text that is so
--------- long that it's 
 wrapping around the image
public class MyLeadingMarginSpan2 implements LeadingMarginSpan.LeadingMarginSpan2 {

int lines;
int offset;

public MyLeadingMarginSpan2(int lines, int offset) {
    this.lines = lines;
    this.offset = offset;
}

@Override
public int getLeadingMarginLineCount() {
    return lines;
}

@Override
public int getLeadingMargin(boolean first) {
    return first ? offset : 0;
}

@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) {

    }
}
并在代码中这样使用它:

float textLineHeight = textView.getPaint().getTextSize();
int lines = (int) (imageView.getMeasuredHeight() / textLineHeight) + 1;
int offset = imageView.getMeasuredWidth();

SpannableString text = new SpannableString("Text that is so long that it's wrapping around the image");
text.setSpan(new MyLeadingMarginSpan2(lines, offset), 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(text);

如果您想为非常旧版本的Android(<2.2)提供额外的回退,您可以查看以下类似问题的答案:

这里提供了一个很好的答案: 我希望这有帮助

也看看 github库

<uk.co.deanwild.flowtextview.FlowTextView
    android:id="@+id/ftv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:padding="10dip"
            android:src="@drawable/android"/>
</uk.co.deanwild.flowtextview.FlowTextView>

这里提供了一个很好的答案:我希望这有帮助