[英]Linear Layout going out of bounds
我有以下布局作為 RecyclerView 項目,由圖像和文本組成:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/library_list_element"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_margin="10dp"
android:src="@drawable/ic_delete_black_18dp"
>
</ImageButton>
<TextView
android:id="@+id/folderName"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:maxLines="3"
android:minLines="1"
android:textAppearance="?attr/textAppearanceBody1"
android:textSize="14sp"
tools:text="/sdcard/somepath/somewhere" />
</LinearLayout>
我想把按鈕放在文本之后。 如果我顛倒文本/按鈕的順序,文本會占用所有空間並且按鈕超出范圍。 我知道我可以手動指定文本的大小,但這不是很干凈。 你怎么做才能有以下布局? :
<--------------------------Text--------------------------><-----Button----->
Wrapping content 50dp
您可以在 TextView 上使用layout_weight="1"
來實現此目的。
<TextView
android:id="@+id/folderName"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:maxLines="3"
android:minLines="1"
android:textAppearance="?attr/textAppearanceBody1"
android:textSize="14sp"
tools:text="/sdcard/somepath/somewhere" />
<ImageButton
android:id="@+id/button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_margin="10dp"
android:src="@drawable/ic_delete_black_18dp" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/library_list_element"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal">
<TextView
android:id="@+id/folderName"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:maxLines="3"
android:minLines="1"
android:textAppearance="?attr/textAppearanceBody1"
android:textSize="14sp"
tools:text="/sdcard/somepath/somewhere" />
<ImageButton
android:id="@+id/button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_margin="10dp"
android:src="@drawable/ic_delete_black_18dp"/>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.