Reputation: 655
I am trying to add button in center (in between the view) but when I add it just below the Textview and AutoCompleteTextView, may I give padding or margin hardcoded? I need "ok" button in between the view (horizontal and vertical center).
Layout XML below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity=""
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choose station"
android:layout_marginLeft="20dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<AutoCompleteTextView
android:id="@+id/item_autoComplete"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="" >
<requestFocus />
</AutoCompleteTextView>
</LinearLayout>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="ok"
android:id="@+id/item_buttonId"/>
</LinearLayout>
Upvotes: 0
Views: 79
Reputation: 3356
android:layout_gravity="center"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity=""
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choose station"
android:layout_marginLeft="20dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<AutoCompleteTextView
android:id="@+id/item_autoComplete"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="" >
<requestFocus />
</AutoCompleteTextView>
</LinearLayout>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="ok"
android:layout_gravity="center"
android:id="@+id/item_buttonId"/>
</LinearLayout>
Upvotes: 1
Reputation: 2609
I think your looking for this.Choose some margin or use RelativeLayout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="top"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choose station"
android:layout_marginLeft="20dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<AutoCompleteTextView
android:id="@+id/item_autoComplete"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="100dp"
android:text="" >
<requestFocus />
</AutoCompleteTextView>
</LinearLayout>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="ok"
android:layout_gravity="center"
android:id="@+id/item_buttonId"/>
</LinearLayout>
Upvotes: 0