我有一個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