layout_alignParentBottom not working as expected - android

I am trying to get a couple of buttons to attach to the bottom of the screen.
For some reason they are attaching themselves to the previous view:
As you can see the buttons are overwriting the previous view.
This is the layout I use:
<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:text_field_element="http://schemas.android.com/apk/res-auto"
xmlns:button_element="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:orientation="vertical"
>
<LinearLayout android:id="#+id/data_entry"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<com.applicat.meuchedet.views.TextFieldElement
android:id="#+id/dental_clinics_search_screen_clinic_type_selector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
text_field_element:prompt="#string/dental_clinic_search_screen_dental_clinic_type_prompt"
text_field_element:initial_text="#string/dental_clinic_type_initial"
text_field_element:cursor_visible="false"
/>
<include
layout="#layout/separator_element"
/>
<com.applicat.meuchedet.views.LocationSelector
android:id="#+id/dental_clinics_location_selector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<include
layout="#layout/separator_element"
/>
<com.applicat.meuchedet.views.TimeSelector
android:id="#+id/dental_clinics_time_selector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<include
layout="#layout/separator_element"
/>
</LinearLayout>
<com.applicat.meuchedet.views.ButtonElement
android:id="#+id/dental_clinics_search_screen_search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
button_element:margin_bottom="10"
/>
<com.applicat.meuchedet.views.ClearButtonElement
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/dental_clinics_search_screen_search_button"
android:layout_alignParentBottom="true"
button_element:margin_bottom="10"
/>
</RelativeLayout>
separator_element.xml
<?xml version="1.0" encoding="UTF-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:layout_marginBottom="15dip"
android:src="#drawable/form_separator"
>
</ImageView>
============================================================================
Edit:
So, it seems that the problem is caused by the fact that the view is put into a ScrollView. We need the ScrollView due to the possibility of small screens.
For some reason it sets the size wrong or something and puts the buttons just below the fields instead of at the very bottom.

Related

Android LinearLayout with Button and FrameLayout using the Maximum Height

I am trying to make a layout where there are a LinearLayout and inside it I want a FrameLayout and a button.
I want the button to use the bottom of the linearlayout and to use the maximum width and the enough height for the button, using wrap content.
The other component, the FrameLayout I want to use it the remaining part of the screen.
How can I do it?
Here it the layout so far..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="snapIt"
android:text="#string/Capture" />
</LinearLayout>
Is not showing the button :s
Thanks alot in advance ;)
Better to work out with relative layout with button aligned to parent bottom and your frame layout above it occupying the rest space of the screen.Like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button_capture"/>
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
use the following xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"
android:text="capture" />
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button_capture"
/>
</RelativeLayout>
i am just trying to make these layout, after compare my layout code and your layout code, i find a different code, there is in my code. Did you missing it or just move it away cause it useless from the layout code ?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<FrameLayout
android:id="#id/flayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world">
</FrameLayout>
</LinearLayout>

Button doesn't appear in android appwidget layout

I have this xml file as a layout of an appwidget:
<?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="vertical"
android:background="#android:color/black" >
<!-- ListView to be shown on widget -->
<ListView
android:id="#+id/listViewWidget"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/refresh_appwidget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="refresh"
/>
</LinearLayout>
The button is not displayed, and I don't know the cause. I tested layout_with match_parent but always the same result.
How can I fix this issue?
Set a fixed height for the listview for example android:layout_height="400dp" in LinearLayout.
Or use a RelativeLayout
Or add your button as a footer to listview. So you can see the button when you scroll down
Or add your button as a header to listview.
With Relative layout you can place the button at the top or button and relative tot eh button you can place your listview.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="#android:color/black"
android:layout_height="fill_parent" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Button" />
<ListView
android:id="#+id/listView1"
android:layout_above="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
</ListView>
</RelativeLayout>
Try with RelativeLayout:
<?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="wrap_content"
android:orientation="vertical"
android:background="#android:color/black" >
<!-- ListView to be shown on widget -->
<ListView
android:id="#+id/listViewWidget"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/refresh_appwidget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="refresh"
/>
</RelativeLayout>
I try and see the Button but dont see the List

Aligning ViewPager and TextView Vertically

<?xml version="1.0" encoding="utf-8"?>
<!-- Layout-Normal-Portrait -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/thumb_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<android.support.v4.view.ViewPager
android:id="#+id/mypager"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_above="#id/sum_layout"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</android.support.v4.view.ViewPager>
</RelativeLayout>
<RelativeLayout
android:id="#+id/sum_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#id/thumb_layout" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="#string/lorem__ipsum"
android:textColor="#color/black" />
</RelativeLayout>
</RelativeLayout>
As soon as I run the program, it shows a error in the editor saying "error: Error: No resource found that matches the given name (at 'layout_above' with value '#id/sum_layout')." which is at line 22 in this code.
Can any one tell, what is wrong?
I wonder why you are making it so complex.
Anyways here is corrected snippet
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout-Normal-Portrait -->
<RelativeLayout 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" > <---No need to specify android:orientation
<android.support.v4.view.ViewPager
android:id="#+id/mypager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/textView" />
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:padding="6dp"
android:text="Hello"
android:textColor="#android:color/black" /> <---Place your text String here
</RelativeLayout>
use #+id/sum_layout
and clean Project and run again!
This is because you declare sum_layout id AFTER its first reference.
The best solution is to declare it in the /res/values/ids.xml like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="sum_layout" />
</resources>
And then reference it in all your layouts without the + keyword
<android.support.v4.view.ViewPager
android:layout_above="#id/sum_layout"
/>
And
<RelativeLayout android:id="#id/sum_layout" />
Try This
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/mypager"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</android.support.v4.view.ViewPager>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:textColor="#color/black" />
When you are using relative layout, you are relating the controls with each other.when you add any control you add next control with respect to the control defined before.Likewise here you have defined view pager layout which is under layout having id #+id/sum_layout. but you have defined layout #+id/sum_layout under view pager.so it doesn't get id #+id/sum_layout,so how it will set view pager under the text view.first of all add the view and then add to its under/above.Here is your mistake:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<android.support.v4.view.ViewPager
android:id="#+id/mypager"
android:layout_width="fill_parent"
android:layout_height="300dp">
</android.support.v4.view.ViewPager>
<TextView
android:id="#+id/mytext"
android:text="#string/lorem__ipsum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/mypager"/>
</RelativeLayout>
Set the layout according to this wherever you have to keep to its below or above.
hope it will help you.

How to make a edittext view fill the parent element in android

I have two edittext views. One of them has only one line, its the title. But the other one should fill the linearlayout to the end, but it doesn't.
I updated the code so this is my whole xml for this app. I hope someone can find what's wrong. The part that i want to form like this is the part inside the LinearLayout named addView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#ffffff">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/addButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/addbuttonstyle"
android:layout_weight="20"/>
<ImageView
android:id="#+id/titleView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/titleview"
android:layout_weight="60"/>
<Button
android:id="#+id/orderButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/orderbuttonstyle"
android:layout_weight="20"/>
</LinearLayout>
<FrameLayout
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/addView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="#+id/textBoxTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="note title"
android:singleLine="true"
/>
<EditText
android:id="#+id/textBoxContent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hint="content"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/backgroundLayout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/background"
/>
</FrameLayout>
I changed textBoxTitle's height to wrap_content and I see this:
Is this what you were hoping for? Also if you want content to appear in the upper-left corner use this attribute:
<EditText
...
android:gravity="top"
/>
So i found what was wrong.
I needed to set layout_height (of the textBoxContent view) to 0dp and layout_weight (of the textBoxContent view) to 1.
The first view should have android:layout_width="wrap_content"

How to add a layout in another one?

I need to hold my every view in one layout, so that i can move them all at once... But when i tried to put them all in a layout which should be in another main layout, they cannot be seen. What am i doing wrong?
I found out that the layout called leftLayout cannot be seen. I made different colours of layouts and it showed me the main one, called menu. I tried visibility true but it didn't work as well.
My design page is like this:
It should appear like this, but i see only white window when i compile...
Here's my Xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/leftLayout"
android:addStatesFromChildren="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="70dp"
android:orientation="vertical" >
<TextView
android:id="#+id/leftMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:enabled="true"
android:text="Left Menu"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<ListView
android:id="#+id/list"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginTop="70dp"
android:enabled="true" >
</ListView>
</RelativeLayout>
</RelativeLayout>
Solved! I figured out that i was just doing mistake in java codes, while setting margin. So here the code's allright.
In relative layout you always need specify the location of each child with respect to the parent or the between the children. Since you have specified the layout all the layouts will be copied one over the other. You can use child alignment options like "ABOVE", "BELOW" w.r.t to other layouts.
The below code looked like what you wanted,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/leftLayout"
android:addStatesFromChildren="true"
android:layout_width="100dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_alignleft="#+id/menu" >
<TextView
android:id="#+id/leftMenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:enabled="true"
android:text="Left Menu"
android:layout_weight="0"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<ListView
android:id="#+id/list"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:enabled="true"
android:layout_marginTop="50dp"
android:layout_weight="1"
android:layout_below="#+id/leftMenu" >
</ListView>
</RelativeLayout>
</RelativeLayout>
You are using a relative layout yet you have not specified the location of the child views relative to each other.
In Relative layout you must specify this, look here: http://developer.android.com/resources/tutorials/views/hello-relativelayout.html
Did you tried with LinearLayouts?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<LinearLayout
android:id="#+id/leftLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="70dp"
android:orientation="vertical" >
<TextView
android:id="#+id/leftMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:enabled="true"
android:text="Left Menu"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="70dp"
android:enabled="true" >
</ListView>
</LinearLayout>
</LinearLayout>

Categories

Resources