Sorry if I'm asking such a basic question. I have tried to google all morning, and read through the documentations at developer.android.com, but I couldn't find a solution.
In short, I would like to make an interface that looks like this:
This is what I have so far:
Now, I'm trying to bring the 2 buttons to the next line, but I still have no luck with that. If I change the android:orientation="horizontal" to "vertical", everything was aligned vertically. I tried to bring the line android:orientation="vertical" inside the Button tag, but that didn't seem to work.
What else can I try? Would somebody give me a few pointers? (I'm new at Android development and all these XML stuff).
Below is my XML code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<EditText android:id="@+id/txt_Input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/txt_Input"
android:layout_weight="4"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_Send"
android:layout_weight="1"
android:onClick="sendMessage"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_Send"
android:layout_weight="1"
android:onClick="sendMessage"
/>
</LinearLayout>
To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .
Weight can only be used in LinearLayout . If the orientation of linearlayout is Vertical, then use android:layout_height="0dp" and if the orientation is horizontal, then use android:layout_width = "0dp" . It'll work perfectly.
In a nutshell, layout_weight specifies how much of the extra space in the layout to be allocated to the View. LinearLayout supports assigning a weight to individual children. This attribute assigns an "importance" value to a view, and allows it to expand to fill any remaining space in the parent view.
Just use RelativeLayout, and your buttons should look something like this:
<Button
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_Send"
android:onClick="sendMessage"
android:layout_below="@+id/txt_Input"
android:layout_alignParentLeft="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_Send"
android:onClick="sendMessage"
android:layout_below="@+id/txt_Input"
android:layout_toRightOf="@+id/send"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With