【发布时间】:2014-03-13 13:50:06
【问题描述】:
我的问题与此类似
How to stop a GridView from cropping my images?
我使用 Flowlayout 来创建标签云,我能够创建它,我正在膨胀文本视图,因为文本可以变化,我已经看到所有使用新行的示例都有固定的布局 xml。如何在膨胀的文本视图中实现新行。
【问题讨论】:
标签: android flowlayout
我的问题与此类似
How to stop a GridView from cropping my images?
我使用 Flowlayout 来创建标签云,我能够创建它,我正在膨胀文本视图,因为文本可以变化,我已经看到所有使用新行的示例都有固定的布局 xml。如何在膨胀的文本视图中实现新行。
【问题讨论】:
标签: android flowlayout
FlowLayout.LayoutParams 对象上的新行标志似乎在运行时不可修改。您将需要修改库本身以添加此功能,或者在需要使用换行 xml 扩展 TextView 时保留单独的布局文件。
如果您希望将文本分成两行并继续使用 FlowLayout,您将需要为两个单独的 TextView 充气,一个用于第一行,一个用于第二行。您还需要手动计算可以在屏幕上显示的文本数量。
【讨论】:
父布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.example.customns"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
tools:context=".CustomActivity"
android:orientation="vertical">
<com.example.customns.FlowLayout
android:id="@+id/loadlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
</com.example.customns.FlowLayout>
</RelativeLayout>
要在父级中膨胀的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.example.customns"
android:id="@+id/buttonContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@color/blue"
android:orientation="horizontal" >
<TextView
app:layout_newLine="true"
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
layout_newLine 在膨胀布局中不起作用,如果我在父布局中拥有所有文本视图,则该布局有效。请有任何建议
【讨论】: