Android even vertical spacing between widgets - android

I have a fragment layout that looks like this:
The top 3 rows are spaced nicely, but the age and sex rows are too short vertically. If I were to hard code a vertical size for the entire layout, is there a way to ensure every item is evenly spaced vertically? Currently, due to the different widget types being used, the bottom too dont look very nice
Here is the code for my layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Research Assistant:" />
<EditText
android:id="#+id/input_ra"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:ems="10"
android:inputType="textCapWords"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Subject Number:" />
<EditText
android:id="#+id/input_subnum"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:ems="10"
android:inputType="text"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Condition:" />
<EditText
android:id="#+id/input_condition"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:ems="10"
android:inputType="number"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Age:" />
<Spinner
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/input_age_spinner"
android:layout_weight="0.6" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Sex:" />
<RadioGroup
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:id="#+id/input_button_male"
android:paddingRight="10dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:id="#+id/input_button_female"
android:paddingRight="10dp"/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="50dp">
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.75"
android:orientation="horizontal" >
<Button
android:id="#+id/input_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:text="Save" />
<Button
android:id="#+id/input_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:text="Reset" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Try this. Each row view is equally apart from each other.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="20dp"
android:weightSum="12"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:gravity="center"
android:orientation="horizontal"
android:layout_weight="2" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Research Assistant:" />
<EditText
android:id="#+id/input_ra"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:textAppearance="#android:style/TextAppearance.Medium"
android:ems="10"
android:inputType="textCapWords"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:gravity="center"
android:orientation="horizontal"
android:layout_weight="2"
android:weightSum="1" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Subject Number:" />
<EditText
android:id="#+id/input_subnum"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:ems="10"
android:inputType="text"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:gravity="center"
android:layout_weight="2"
android:weightSum="1" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Condition:" />
<EditText
android:id="#+id/input_condition"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:ems="10"
android:inputType="number"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="2"
android:gravity="center"
android:weightSum="1" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Age:" />
<Spinner
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/input_age_spinner"
android:layout_weight="0.6" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:gravity="center"
android:orientation="horizontal"
android:layout_weight="2"
android:weightSum="1" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Sex:" />
<RadioGroup
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:id="#+id/input_button_male"
android:paddingRight="10dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:id="#+id/input_button_female"
android:paddingRight="10dp"/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:gravity="center"
android:layout_weight="2"
android:weightSum="1">
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="0.75"
android:orientation="horizontal" >
<Button
android:id="#+id/input_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:text="Save" />
<Button
android:id="#+id/input_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:text="Reset" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Hope this works for you.

Perhaps you could consider using weightSum and weight attribute to evenly distribute it.
Below is the edited code based on that. Noted your height would be now 0dp, and I give more weight to the last buttons.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10"
android:padding="20dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Research Assistant:" />
<EditText
android:id="#+id/input_ra"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:ems="10"
android:inputType="textCapWords"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Subject Number:" />
<EditText
android:id="#+id/input_subnum"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:ems="10"
android:inputType="text"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Condition:" />
<EditText
android:id="#+id/input_condition"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:ems="10"
android:inputType="number"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Age:" />
<Spinner
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/input_age_spinner"
android:layout_weight="0.6" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Sex:" />
<RadioGroup
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:id="#+id/input_button_male"
android:paddingRight="10dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:id="#+id/input_button_female"
android:paddingRight="10dp"/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:paddingTop="50dp"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.75"
android:orientation="horizontal" >
<Button
android:id="#+id/input_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:text="Save" />
<Button
android:id="#+id/input_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:text="Reset" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Related

Weighted layout expands too much. How to fix it?

I'm making a list of schedules. I use weightsum and layout_weight but the fields are too much expanded. How to fix it. Here is the code i=of list item There is a big space between from-to to no of seats.
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#layout/layout_bg_fav_bus_left"
android:layout_weight="7"
android:weightSum="7"
android:gravity="left"
android:layout_gravity="left">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="top"
android:orientation="horizontal"
android:layout_weight="3">
<TextView
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#color/genaral_blue"
android:id="#+id/txt_route"
android:text="Route"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:gravity="bottom"
android:layout_weight="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt_avail_seats"
android:textSize="15dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="2dp"
android:textColor="#color/genaral_blue"
android:text="Available"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="2">
<ImageView
android:layout_width="32dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:src="#drawable/booking"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginBottom="2dp"
android:textColor="#color/genaral_blue"
android:textSize="15dp"
android:text="Book Your Seat"
android:gravity="center_vertical" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:weightSum="3"
android:background="#layout/layout_bg_fav_bus_right"
android:orientation="vertical"
android:layout_gravity="right"
android:gravity="right">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="5"
android:id="#+id/txt_time_now"
android:textColor="#color/alice_blue"
android:textSize="45dp"
android:textAlignment="center"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_marginBottom="3dp"
android:text="20"
android:id="#+id/txt_time_next1"
android:textColor="#color/alice_blue"
android:textSize="15dp"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30"
android:layout_marginBottom="3dp"
android:textColor="#color/alice_blue"
android:id="#+id/txt_time_next2"
android:textSize="15dp"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Not able to display buttons in the screen

I am having a screen which has many layouts having title,list view ,comment and buttons but buttons are not getting displayed at all,after list view display I am getting a huge amount of empty space after which comment is getting displayed and buttons are not seen ,this is my code.
<?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"
android:background="#android:color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_margin="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="12345617890" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:fontFamily="#android:color/black"
android:text="Ramakrisha Tripati" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="9876543210" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1"
android:layout_margin="10dp"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="13/1/2015" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Rohit Sharma" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="55dp"
android:orientation="horizontal"
android:background="#android:color/holo_orange_light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="item#\nstyle#"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="M Wt\nD Wt\nCS Wt"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Making\nD Rate\nCS Rate"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Margin\nDis %\nDiscount"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GT\nFSP"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="#00000000"
android:dividerHeight="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp"
android:text="Comment" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:ems="10"
android:hint="Comment goes here"
android:inputType="textMultiLine" />
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="accept"
android:src="#drawable/accept"
/>
</LinearLayout>
I have modified your layout code and now the button has appeared.
<?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:background="#android:color/white"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="12345617890" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:fontFamily="#android:color/black"
android:text="Ramakrisha Tripati" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="9876543210" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="13/1/2015" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Rohit Sharma" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="55dp"
android:background="#android:color/holo_orange_light"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="item#\nstyle#" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="M Wt\nD Wt\nCS Wt" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Making\nD Rate\nCS Rate" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Margin\nDis %\nDiscount" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="GT\nFSP" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="#00000000"
android:dividerHeight="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comment"
android:textSize="25dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:ems="10"
android:hint="Comment goes here"
android:inputType="textMultiLine" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:onClick="accept"
android:src="#drawable/accept" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Just put your main LinearLayout inside scrollview and you will see thr buttons.
And if not so maybe your image is so small or transparent.
check with another image maybe.

Android layout creation help needed

I'm trying to make a "gamepad" with WASD and arrows in each side like this:
but instead of the arrow pad being below WASD i want them to be in the same "line" with the WASD in the left and arrows in the right
can someone help me with this (i'm not posting my code since it's garbage and not even close to the solution, it's just to illustrate what i'm trying to do)?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/menubg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|top"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="W" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|top"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="A" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="S" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="D" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|top"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="↑" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|top"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="←" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="↓" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="→" />
</LinearLayout>
</LinearLayout>
try this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2" >
<LinearLayout
android:id="#+id/mainArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/keypad"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|top"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="W" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|top"
android:orientation="horizontal"
android:weightSum="9" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:focusable="false"
android:text="A" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:focusable="false"
android:text="S" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:focusable="false"
android:text="D" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/arrow"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|top"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="↑" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|top"
android:orientation="horizontal"
android:weightSum="9" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:focusable="false"
android:text="←" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:focusable="false"
android:text="↓" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:focusable="false"
android:text="→" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

How to create a form that have autolookup in Android

I want to use auto look up for searching .
I have partially created this layout . This is my XML code.
Now how can i use autol lookup in this?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:src="#drawable/logo_demo" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView1"
android:layout_marginTop="10dp"
android:background="#drawable/flight_bar"
android:orientation="horizontal" >
<TextView
android:id="#+id/roundtripTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="23dp"
android:layout_marginTop="5dp"
android:layout_weight="0.01"
android:text="Round trip"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/OneWayTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="23dp"
android:layout_marginTop="5dp"
android:layout_weight="0.01"
android:text="OneWay"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/multicityTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="23dp"
android:layout_marginTop="5dp"
android:layout_weight="0.03"
android:text="MultiCity"
android:textColor="#android:color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:id="#+id/linearLayout4"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout1"
android:background="#drawable/from2"
android:orientation="horizontal" >
<TextView
android:id="#+id/fromTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="7dp"
android:layout_weight=".05"
android:text="From" />
<TextView
android:id="#+id/toTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="7dp"
android:layout_weight=".05"
android:text="To" />
</LinearLayout>
</RelativeLayout>
i have to use a auto look up box same below to the to i have to use autolook up and in the middle of both there will be image .So i have done till from and to part now i am not able to create to separate auto look up box below from and to.
Try this layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/imageView1"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/roundtripTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="#FF0000FF"
android:gravity="center"
android:text="Round trip"
android:textColor="#android:color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/OneWayTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="1dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="#FF0000FF"
android:gravity="center"
android:text="OneWay"
android:textColor="#android:color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/multicityTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="1dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="#FF0000FF"
android:gravity="center"
android:text="MultiCity"
android:textColor="#android:color/white"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout1"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical" >
<EditText
android:id="#+id/fromTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:gravity="center_horizontal"
android:hint="From" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="LON"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="London Great Britain"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/darker_gray"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical" >
<EditText
android:id="#+id/toTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:gravity="center_horizontal"
android:hint="To" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="DXB"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Dubai United Arab Emirates"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Edit
Put below layout after "from/to" layout.
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/linear3"
android:orientation="horizontal" >
<AutoCompleteTextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="bottom"
android:text="LON" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/darker_gray"
android:src="#drawable/ic_launcher" />
<AutoCompleteTextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="bottom"
android:text="DXB" />
</LinearLayout>

Android Linear Layout issue

I have a problem with dividing the LinearLayout(Horizontal) into three columns (vertical columns).
Can someone look into the XML and advise ?
XML below:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="40"
android:orientation="vertical" >
<ImageButton
android:id="#+id/ibTakeCheckPhoto"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:src="#drawable/camera" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="fill_parent"
android:background="#android:color/darker_gray" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="30"
android:orientation="vertical" >
<TextView
android:id="#+id/checkLayoutIDTV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Check Number"
android:textStyle="bold" />
<TextView
android:id="#+id/checkLayout_amountTV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Amount"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="30"
android:orientation="vertical" >
<EditText
android:id="#+id/checkLayoutIDET"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Check No."
android:inputType="number" >
</EditText>
<EditText
android:id="#+id/checkLayout_amounET"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="5"
android:hint="Amount"
android:inputType="number" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="24.33"
android:orientation="vertical" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/checkLayoutIDTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check Number"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/checkLayout_amountTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Amount"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow6"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/EditText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:hint="Amount"
android:inputType="number" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/checkLayoutIDET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="edit2"
android:inputType="number" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/checkLayout_amounET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="5"
android:hint="Amount"
android:inputType="number" >
<requestFocus />
</EditText>
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
may b it fulfill your requirement..
Use android:layout_width="fill_parent" instead of android:layout_width="0dp" in ImageButton, TextView and EditText.
Resulting layout will look like this
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="40"
android:orientation="vertical" >
<ImageButton
android:id="#+id/ibTakeCheckPhoto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:src="#drawable/camera" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="fill_parent"
android:background="#android:color/darker_gray" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="30"
android:orientation="vertical" >
<TextView
android:id="#+id/checkLayoutIDTV"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Check Number"
android:textStyle="bold" />
<TextView
android:id="#+id/checkLayout_amountTV"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Amount"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="30"
android:orientation="vertical" >
<EditText
android:id="#+id/checkLayoutIDET"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Check No."
android:inputType="number" >
</EditText>
<EditText
android:id="#+id/checkLayout_amounET"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="5"
android:hint="Amount"
android:inputType="number" />
</LinearLayout>
</LinearLayout>
And extract hardcoded strings to res/values/strings.xml
i think this is what you wanted
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="10" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="vertical" >
<ImageButton
android:id="#+id/ibTakeCheckPhoto"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="left"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="fill_parent"
android:background="#android:color/darker_gray" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:orientation="vertical" >
<TextView
android:id="#+id/checkLayoutIDTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Check Number"
android:textStyle="bold" />
<TextView
android:id="#+id/checkLayout_amountTV"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Amount"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="fill_parent"
android:background="#android:color/darker_gray" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:orientation="vertical" >
<EditText
android:id="#+id/checkLayoutIDET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Check No."
android:inputType="number" >
</EditText>
<EditText
android:id="#+id/checkLayout_amounET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="5"
android:hint="Amount"
android:inputType="number" />
</LinearLayout>

Categories

Resources