【发布时间】:2017-09-11 10:34:28
【问题描述】:
当第一个文本的长度增加时,具有水平方向的 Android 线性布局使下一个 TextViews 不可见。如果第一个 textview 长度超过一行,则剩余的 textviews 将不可见。我只想环绕文本,即,如果第一个文本视图的长度增加,则其余视图应位于第一个视图之下。
我可以在不以编程方式更改方向的情况下实现吗?
我的代码如下:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.mikhaellopez.circularimageview.CircularImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="15dp"
android:scaleType="centerCrop"
app:civ_border_color="@color/colorAccent"
app:civ_border_width="5dp"
app:civ_border="true"
android:src="@drawable/user"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginStart="80dp"
android:layout_marginEnd="35dp"
android:layout_marginRight="35dp"
android:layout_marginTop="15dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:maxLines="2"
android:textColor="@android:color/black"
android:textSize="16sp"
android:ellipsize="end"
android:layout_margin="3dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="3dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:ellipsize="end"
android:maxLines="1"
android:textSize="14sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/period"
android:textSize="16sp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/views"
android:textSize="14sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/period"
android:textSize="16sp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hoursago"
android:textSize="14sp"/>
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="@+id/popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center"
android:background="@null"
android:clickable="true"
android:padding="5dp"
android:layout_margin="5dp"
android:layout_centerInParent="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="@drawable/ic_overflow_grey_24dp" />
</RelativeLayout>
我得到的屏幕是
【问题讨论】:
-
是的,你可以使用HorizontalScrollView来实现下一个textview,或者你可以固定第一个TextView的宽度。
-
你可以尝试给每个 texview 赋予权重
-
虽然我给出了权重,但文本在指定的权重内对齐。我只想环绕文本,即,如果第一个 textview 的长度增加,则其余视图应位于第一个视图下
标签: android textview android-linearlayout