[英]How can TextView be aligned right next to a Buttin in LinearLayout
I tried to find a solution but I wasn't be able. 我试图找到一种解决方案,但我无法做到。 The question is simple, how align a TextView
and a Button in a LinearLayout
. 问题很简单,如何在LinearLayout
对齐TextView
和Button。
Something like this: 像这样:
I tried this but it doesn't work: 我试过了,但是没有用:
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<EditText
android:layout_width="wrap_content"
android:gravity="center_horizontal"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Name"
android:ems="10"
android:id="@+id/editText"
android:textAppearance="@style/TextAppearance.AppCompat.Light.SearchResult.Subtitle" />
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button" />
</LinearLayout>
Thanks in advance! 提前致谢!
You need to set 你需要设置
android:orientation="horizontal"
in your LinearLayoutandroid:orientation="horizontal"
在您的LinearLayout中
try this 尝试这个
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="my edit text"/>
<Button
android:text="Add"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
this will work in your case thanks 这将在您的情况下工作 谢谢
Replace in your LinearLayout orientation 沿LinearLayout方向替换
android:orientation="vertical"
to 至
android:orientation="horizontal"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.