[英]Linear Layout going out of bounds
I have the following layout as a RecyclerView item, composed of an image and a text:我有以下布局作为 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>
I want to put the button after the text.我想把按钮放在文本之后。 If I invert the order of the Text/Button, the text is taking all the space and the button goes out of bounds.如果我颠倒文本/按钮的顺序,文本会占用所有空间并且按钮超出范围。 I know I can specify the size of text manually, but that's not very clean.我知道我可以手动指定文本的大小,但这不是很干净。 How do you do to have the following layout?你怎么做才能有以下布局? : :
<--------------------------Text--------------------------><-----Button----->
Wrapping content 50dp
You can use layout_weight="1"
on TextView to achieve this.您可以在 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.