我有一個串列視圖,每個串列項都設計在RelativeLayout. 在每個相對布局中,我有三個按鈕和兩個文本視圖。一切都應該排成一排。第一個文本視圖應該左對齊,而按鈕位于與父級末尾對齊的水平行中,第二個文本視圖直接位于它們之前。我的問題是,主文本視圖中很長的文本與按鈕和第二個文本視圖重疊。如果足夠長,文本確實會分成第二行,但我希望它中斷。
現在我已經實作了串列看起來像這樣。可悲的是,文本不會在按鈕/相關文本之前中斷,而只會在父項的末尾。
以前我有一個layout_marginEndof 160dp,它在我的個人手機上運行良好,但從那以后,我收到了來自擁有其他品牌的其他手機的用戶的錯誤報告。
我的代碼如下所示:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@ id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:textIsSelectable="false"
android:textSize="@dimen/listItemTextSize"
tools:ignore="UnusedIds" />
<LinearLayout
android:id="@ id/buttonLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
tools:ignore="RelativeOverlap,UnusedIds">
<TextView
android:id="@ id/amountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="8dp"
android:textIsSelectable="false"
android:textSize="@dimen/listItemTextSize" />
<ImageButton
android:id="@ id/subtractButton"
style="@style/Theme.ShoppingList.ImageButton"
android:background="@drawable/ic_minus"
android:contentDescription="@string/mainSubtractButtonDescription" />
<ImageButton
android:id="@ id/addButton"
style="@style/Theme.ShoppingList.ImageButton"
android:background="@drawable/ic_plus"
android:contentDescription="@string/mainAddButtonDescription" />
<ImageButton
android:id="@ id/deleteButton"
style="@style/Theme.ShoppingList.ImageButton"
android:background="@drawable/ic_trash"
android:contentDescription="@string/mainDeleteButtonDescription" />
</LinearLayout>
</RelativeLayout>
預先感謝您的幫助!
uj5u.com熱心網友回復:
將android:layout_alignParentStart="true"和添加android:layout_toStartOf="@id/buttonLayout"到名稱TextLayout。
這將在 LinearLayout 之前破壞 nameTextView 并保持 nameTextView 的文本左對齊。
uj5u.com熱心網友回復:
添加android:layout_toStartOf="@id/buttonLayout"到名稱TextLayout。這將使它在該線性布局之前停止并在那里中斷。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/406826.html
標籤:
