Android: Views in ScrollView doesn't appear past empty LinearLayout - android

On Android 4, I have a simple ScrollView which presents a form to fill in. Inside the view I have a number of buttons, then this Layout,
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/layoutImages" />
then more buttons. The layout always stops rendering at the LinearLayout. If I move the layout down the list of views, all views above it appear. I can reference the other layouts in code nicely so they are there, just not visible.
Do I need to do something to the LinearLayout to prevent it from stopping the rendering of all the subsequent views?
For reference, here's the full layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:id="#+id/scrView">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background_selector">
<Button
android:text="Call Crime Stoppers"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/btnCall"
android:layout_marginRight="3dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="5dp"
android:background="#drawable/blue_button_selector"
android:textSize="25dp"
android:textColor="#color/white"
android:drawableLeft="#drawable/phone_element" />
<TextView
android:text="About the Incident:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/lblDescriptionTop"
android:layout_marginTop="15dp" />
<Button
android:text="Take a Picture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/btnPicture"
android:layout_marginRight="3dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="5dp"
android:background="#drawable/blue_button_selector"
android:textSize="25dp"
android:textColor="#color/white"
android:drawableLeft="#drawable/icon_camera" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/layoutImages" />
<Button
android:text="Location Type"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/btnLocationType"
android:layout_marginRight="3dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="5dp"
android:background="#drawable/blue_button_selector"
android:textSize="25dp"
android:textColor="#color/white" />
<Button
android:text="Nature of the Incident"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/btnNature"
android:layout_marginRight="3dp"
android:layout_marginLeft="3dp"
android:background="#drawable/blue_button_selector"
android:textSize="25dp"
android:textColor="#color/white"
android:layout_marginTop="5dp" />
<TextView
android:text="Please Describe:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/lblDescription"
android:layout_marginTop="15dp" />
<EditText
android:inputType="textMultiLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/txtDescription"
android:minHeight="150dp"
android:maxHeight="150dp"
android:layout_marginTop="5dp"
android:minWidth="150dp"
android:maxWidth="150dp" />
<TextView
android:text="Optional Contact Info:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textView1"
android:layout_marginTop="15dp" />
<CheckBox
android:text="Use Phone Number?"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/chkPhone" />
<EditText
android:inputType="phone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/editPhone"
android:hint="Phone Number" />
<CheckBox
android:text="Use Email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/chkEmail" />
<EditText
android:inputType="phone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/editEmail"
android:hint="Email" />
<Button
android:text="Send"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/btnSend"
android:layout_marginRight="3dp"
android:layout_marginLeft="3dp"
android:background="#drawable/blue_button_selector"
android:textSize="25dp"
android:textColor="#color/white"
android:layout_marginTop="15dp" />
</LinearLayout>
</ScrollView>

That is because you have your layout_height set to "fill_parent" so it's taking up the rest of the space below that. That's why it works when it's at the bottom, but not in the middle.
Try either changing it to "wrap_content" or using a RelativeLayout.

Related

Aligning Two LinearLayout Side By Side Inside a CardView

I am trying to align two TextViews OR LinearLayouts side by side in order to reach this cardView:
I have used layout_gravity and layout_weight attributes inorder to solve this situation, but with no luck.
I am open to any other suggestions that may accomplish my goal as log as I can generate cardview dynamicaly using BaseAdapter with ListView in the Activity Code.
I am looking for XML solution.
Here is my xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:padding="5dp">
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
card_view:cardCornerRadius="5sp"
card_view:cardElevation="5sp"
card_view:contentPadding="16dp"
android:orientation="horizontal"
android:layout_weight="2">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="2">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="left"
android:gravity="left"
android:layout_weight="1">
<TextView
style="#style/Base.TextAppearance.AppCompat.Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="16dp"
android:textColor="#ec1c24"
android:text="Model Name" />
<TextView
style="#style/Base.TextAppearance.AppCompat.Body1"
android:id="#+id/plc_ModelName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="36dp"
android:textColor="#666666"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="right"
android:gravity="right"
android:layout_weight="1">
<TextView
android:id="#+id/plc_localIp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp" />
<TextView
android:id="#+id/plc_machineType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="16dp" />
<TextView
android:id="#+id/plc_ModelId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="16dp" />
<TextView
android:id="#+id/plc_Version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Many thanks.
For the part on the right you can use a TableLayout.
Try to play with nesting layouts or switch to ConstraintLayout for better performance. Too many nested layout weights will quickly add up and create performance issues.
You can start fine tuning from the XML provided below. I removed the layout_weight from the CardView, if needed, add it back.
In preview it looks like this:
Layout XML:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
card_view:cardCornerRadius="5sp"
card_view:cardElevation="5sp"
card_view:contentPadding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
style="#style/Base.TextAppearance.AppCompat.Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Model Name"
android:textColor="#ec1c24"
android:textSize="16dp"
android:textStyle="bold" />
<TextView
android:id="#+id/plc_ModelName"
style="#style/Base.TextAppearance.AppCompat.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#666666"
android:textSize="36dp"
android:textStyle="bold"
tools:text="T-Max" />
</LinearLayout>
<TableLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:text="Model ID:"
android:textColor="#ec1c24"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="#+id/plc_ModelId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:textSize="14dp"
tools:text="12345678" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:text="IP:"
android:textColor="#ec1c24"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="#+id/plc_localIp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:textSize="14dp"
tools:text="192.168.0.1" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:text="BS Version:"
android:textColor="#ec1c24"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="#+id/plc_Version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:textSize="14dp"
tools:text="3.0.2.111" />
</TableRow>
</TableLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>

Android - EditText's hint changes View/Layout's size

I have a LinearLayout consisting of 3 LinearLayout's consisting of 2 TextView's and an EditText. When I add a hint to the third EditText I end up with a lot of whitespace between the 2nd and 3rd TextViews and also after the 3rd.
Code and images are below. What could be causing this?
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="#+id/self"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name"
android:layout_marginLeft="5dp"
android:padding="5dp"
android:textSize="22sp"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sample Name"
android:padding="5dp"
android:id="#+id/self_name_show"
android:textSize="22sp"
android:textColor="#0099CC"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="#+id/self_name_edit"
android:inputType="text"
android:hint="#string/enter_name"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/address"
android:layout_marginLeft="5dp"
android:padding="5dp"
android:textSize="22sp"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sample Address"
android:padding="5dp"
android:id="#+id/self_address_show"
android:textSize="22sp"
android:textColor="#0099CC"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/self_address_edit"
android:visibility="gone"
android:inputType="text"
android:hint="#string/enter_address"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/phone"
android:layout_marginLeft="5dp"
android:padding="5dp"
android:autoLink="all"
android:textSize="22sp"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sample Phone"
android:padding="5dp"
android:id="#+id/self_phone_show"
android:textSize="22sp"
android:textColor="#0099CC"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/self_phone_edit"
android:phoneNumber="true"
android:hint="#string/enter_phone"
/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="#string/edit"
android:id="#+id/edit_self_button"
android:onClick="toggleSelfEdit"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="#string/update"
android:id="#+id/update_self_button"
android:visibility="gone"
/>
</LinearLayout>
Without hint:
With hint:
I think you forgot writing the android:visibility="gone" at the third edittext. I tried your xml and when I put visibility="gone" inside the edittext your xml looks like the first screenshot :)

i am unable to lock some part of the screen while using "Scroll View"

i am implementing one data enter screen with many fields.so that i am using scrolling view in my layout.But i want to draw OK button always.but i am unable to lock the some part of the screen.
i need secreen as:
but i am getting picture as either
or
i am adding my layout code below(as shown in last pic) plesae help me .
<?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" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#2E9AFE" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Present Details"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColorHint="#350924"
android:textStyle="bold" />
<TextView
android:id="#+id/tvtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Present Location"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#350924"
android:textStyle="bold" />
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<EditText
android:id="#+id/etPreLoc1"
android:layout_width="fill_parent"
android:layout_height="120dp"
android:layout_gravity="center"
android:ems="10"
android:hint="Where are u now?"
android:inputType="textPostalAddress" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/etPreLoc1"
android:layout_gravity="center"
android:text="Coming By"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#350924"
android:textStyle="bold" />
<EditText
android:id="#+id/mmsComing"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:hint="car/auto/other" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Vehicle details"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#350924"
android:textStyle="bold" />
<EditText
android:id="#+id/etDriver"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:hint="Driver name/vehicle no"
android:inputType="textPersonName" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Expected time to reach by:"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#350924"
android:textStyle="bold" />
<TimePicker
android:id="#+id/timePicker2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_weight="75" />
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/mmsOk"
android:layout_width="fill_parent"
android:layout_height="64dp"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_weight="25"
android:background="#drawable/blackbutton"
android:text="OK"
android:textColor="#android:color/white"
android:textSize="32dp"
android:textStyle="bold" />
</LinearLayout>
You can do that with a RelativeLayout like that. Just put all you views in the linearlayout inside the scrollview.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</RelativeLayout>
Change scrollview height to 0dp and give weight as 1.
Change button layout gravity to bottom instead of center.

why is this xml layout crashing my app?

This layout is used as the layout for items in a listView. I had a really simple layout, and everything was working fine, but now i have changed it a little and it is crashing my app when it tries to load.. Not sure what im doing wrong
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:weightSum="8"
android:layout_width="fill_parent"
android:layout_height="75dp">
<TextView android:id="#+id/priceText"
android:layout_weight="2"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp" />
<LinearLayout
android:layout_weight="5"
android:layout_height="fill_parent"
android:weightSum="2"
android:orientation="vertical">
<TextView android:id="#+id/storeText"
android:layout_width="fill_parent"
android:layout_weight="1"
android:gravity="right|bottom"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView android:id="#+id/distanceText"
android:layout_width="fill_parent"
android:layout_weight="1"
android:gravity="right|top"
android:textSize="16dp"
android:textColor="#545454"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
</LinearLayout>
<TextView
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:text=">"
android:textColor="#000000"
android:textSize="36dp"
android:textStyle="bold"
android:layout_marginRight="5dp" />
</LinearLayout>
When you use android:layout_weight put layout_width="0dip"
Working code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:weightSum="8"
android:layout_width="fill_parent"
android:layout_height="75dp">
<TextView android:id="#+id/priceText"
android:layout_weight="2"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp" />
<LinearLayout
android:layout_weight="5"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:weightSum="2"
android:orientation="vertical">
<TextView
android:id="#+id/storeText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|bottom"
android:textColor="#000000"
android:textSize="22dp"
android:textStyle="bold" />
<TextView
android:id="#+id/distanceText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|top"
android:textColor="#545454"
android:textSize="16dp" />
</LinearLayout>
<TextView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:text=">"
android:textColor="#000000"
android:textSize="36dp"
android:textStyle="bold"
android:layout_marginRight="5dp" />
</LinearLayout>
You need to add android:layout_width=".." and android:layout_height=".."to all the views:
<TextView android:id="#+id/storeText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right|bottom"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView android:id="#+id/distanceText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right|top"
android:textSize="16dp"
android:textColor="#545454"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
</LinearLayout>
<TextView
android:layout_height="fill_parent"
android:layout_width="0dp"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:text=">"
android:textColor="#000000"
android:textSize="36dp"
android:textStyle="bold"
android:layout_marginRight="5dp" />
</LinearLayout>
every element you gave android_layout_weight you didn't give a width. If you gave this weight so the element takes a certain space you should give the layout
android:layout_width="0"
so it takes the weight as width
height and width are required tags for every element
you have missed some layout width and layout height attributes.
i have added in the all items.
Please use the below code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:weightSum="8"
android:layout_width="fill_parent"
android:layout_height="75dp">
<TextView android:id="#+id/priceText"
android:layout_weight="2"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:layout_width="wrap_content"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp" />
<LinearLayout
android:layout_weight="5"
android:layout_height="fill_parent"
android:weightSum="2"
android:layout_width="wrap_content"
android:orientation="vertical">
<TextView android:id="#+id/storeText"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="right|bottom"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView android:id="#+id/distanceText"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="right|top"
android:textSize="16dp"
android:textColor="#545454"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
</LinearLayout>
<TextView
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:text=">"
android:layout_width="fill_parent"
android:textColor="#000000"
android:textSize="36dp"
android:textStyle="bold"
android:layout_marginRight="5dp" />
</LinearLayout>
I don't know exactly what you want to achieve here by this layout but there are few mistake in your xml.
At various places width and height are missing. Consider adding those.
You are adding LinearLayout as parent tag but using RelativeLayout Tags like
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
do consider removing those.
Use properly combination of android:layout_weight="" and android:layout_height="" , android:layout_width=""
Comment if any clarification or help required

Which layout have to use

I am new to android app development.I am developing an android app which is having a design like the following one.Which layout I have to use.If I use Linear layout I cannot place "Product Amount" Textview and Editbox in a stright line.Please help me to solve this.
you can do this using Linear Layout also
Try below 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="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Product Amount"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText1"
android:layout_width="140dp"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content"
>
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<EditText
android:id="#+id/editText2"
android:layout_width="80dp"
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="%"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="TextView" />
<EditText
android:id="#+id/editText3"
android:layout_marginLeft="5dp"
android:layout_width="80dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<EditText
android:id="#+id/editText4"
android:layout_width="80dp"
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="%"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="TextView" />
<EditText
android:id="#+id/editText6"
android:layout_marginLeft="5dp"
android:layout_width="80dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
See below it's give me output like this
You will have to use more than one layout. Your xml will be something like this.
Linear Layout main (Vertical)
Linear Layout1 (Horizontal) - for first row.
Layout 1 ends
Linear Layout2 (Horizontal) - for second row.
Layout 2 ends
Linear Layout3 (Horizontal) - for third row.
Layout 3 ends
Text Sale Amt
Layout main ends
Edit:
<?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:id="#+id/l1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="3dip"
android:layout_weight="1"
android:padding="3dip"
android:text="Name" />
<EditText
android:id="#+id/nameedt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="3dip"
android:layout_weight="1"
android:inputType="textNoSuggestions"
android:padding="3dip" />
</LinearLayout>
<LinearLayout
android:id="#+id/l2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/pwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="3dip"
android:padding="3dip"
android:layout_weight="1"
android:text="Password" />
<EditText
android:id="#+id/pwdedt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="3dip"
android:inputType="textNoSuggestions"
android:layout_weight="1"
android:padding="3dip" />
</LinearLayout>
<TextView
android:id="#+id/pwdhint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="3dip"
android:padding="3dip"
android:layout_weight="1"
android:text="PasswordHint : HINT"
android:layout_gravity="center"/>
</LinearLayout>
You Should use TableLayout, with First Row Having four columns, use col span to extend a column for two columns, add View, where Cell isnt exist.

Categories

Resources