I'm having an issue here, I'm unfamiliar with layouts on android and I can't get this layout to do as I wish.
I would like it to appear as follows:
[Button][Button]
Text Filled Here
Text Filled Here
Text Filled Here
Text Filled Here
Text Filled Here
The TextView is populated via my messagehelper that sends the text to the UI
Eventually my code will be iterating through a list of objects retrieved from a web service and displaying them all on their own rows, with an option to press one and view it on a map.
At the moment, I can only get either the two buttons OR the text to show separately, or all three of them on the same line, not the two buttons on the first line and the text populated downwards!!
Here is my code:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/buttonLayout"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1">
<Button
android:id="@+id/vehicleButton"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="Refresh"
android:onClick="getVehicles" />
<Button
android:id="@+id/logoutButton"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="Logout"
android:onClick="logout" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textLayout"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView
android:id="@+id/textView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
By default, LinearLayout
orientation is horizontal
, you need to change the 1st and 3rd LinearLayout
orientation on your xml
to vertical
.
use android:orientation="vertical"
You can simplify your layout:
EDIT: If by "populated downwards" mean you want text below the buttons:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/vehicleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:onClick="getVehicles"
android:text="Refresh" />
<Button
android:id="@+id/logoutButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/vehicleButton"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/vehicleButton"
android:layout_weight="1"
android:onClick="logout"
android:text="Logout" />
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="false"
android:layout_alignParentTop="false"
android:layout_below="@id/vehicleButton"
android:layout_weight="1"
android:text="Test"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
In order to place textview bottom of each other use orientation as vertical.
And Code will be This
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/buttonLayout"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1">
<Button
android:id="@+id/vehicleButton"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="Refresh"
android:onClick="getVehicles" />
<Button
android:id="@+id/logoutButton"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="Logout"
android:onClick="logout" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textLayout"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
try this...
<?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" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
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.