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
.
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 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
android:orientation="vertical"
to
android:orientation="horizontal"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.