我有一个TextView和一个ImageView,它们之间有一个空格。我希望ImageView位于TextView的右侧,并且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”。现在代码就像我的电脑上一样。 – maf27