【发布时间】:2016-02-27 01:33:29
【问题描述】:
我有一个 TextView 和一个 ImageView,它们之间有一个空格。我希望 ImageView 位于 TextView 的右侧,并且 TextView 动态地更改其大小。我设法做到了,但是如果文本太长,textView 会向左扩展超出其父边界。为什么会这样?我能做些什么来解决它?
<LinearLayout
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:gravity="right|center_vertical">
<TextView
android:id="@+id/received"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="5dip"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="@drawable/received_style"
android:text="dsssssajhhhhhhhhhhhhhhhhhhhoooooooooohsssssssssdhsfsd"
/>
<Space
android:layout_width="5dp"
android:layout_height="0dp"
/>
<ImageView
android:id="@+id/imageView"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/edit" />
</LinearLayout>
【问题讨论】:
-
发现错误! LinearLayout 的 layout_width 是“wrap_content”,而不是“match_parent”。现在代码和我电脑上的一样。
标签: android android-layout android-linearlayout