(i have put the code at the end of my post)
i would like to make a hidden menu.
I don't know if i take the good way.
I have some button visible, some invisible button and at the an another visible button.
One of the button in first layout have to set visible the hidden buttons.
I would like to have the last button just after the first bunch.
But like i have put invisible the Layout so i have an empty space.
I would like when i pressed the button for set visible that the last button go down.
I hope you will understand want i want to do and what i have done.
<?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="fill_parent"
android:orientation="vertical"
android:background="#drawable/fond"
>
<ImageView
android:id="#+id/imageView1"
android:contentDescription="#string/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/top"
android:layout_gravity="top"
android:adjustViewBounds="true"
/>
<LinearLayout
android:layout_below="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/fond2"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3"
>
<Button
android:id="#+id/button_garçon"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/Bg"
android:background="#drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionGarçon"
/>
<Button
android:id="#+id/button_mixte"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/Bm"
android:background="#drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionMixte"
/>
<Button
android:id="#+id/button_fille"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/Bf"
android:background="#drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionFille"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1"
>
<Button
android:id="#+id/button_param"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Bp"
android:background="#drawable/button_green"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionParametre"
/>
</LinearLayout>
<!-- invisible -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="invisible"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Tq"
android:textColor="#000000"
/>
<EditText android:id="#+id/edit_message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/Emc"
android:singleLine="true"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Tpre"
android:textColor="#000000"
/>
<EditText android:id="#+id/edit_message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/Epre"
android:singleLine="true"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Tsuf"
android:textColor="#000000"
/>
<EditText
android:id="#+id/edit_message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/Esuf"
android:singleLine="true"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Tl"
android:textColor="#000000"
/>
<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"
>
<Button android:id="#+id/button_court"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Blc"
android:layout_weight="25"
android:background="#drawable/button_purple"
android:textColor="#ffffff"
android:onClick="actionCourt"
/>
<Button android:id="#+id/button_moyen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Blm"
android:layout_weight="25"
android:background="#drawable/button_purple"
android:textColor="#ffffff"
android:onClick="actionMoyen"
/>
<Button android:id="#+id/button_long"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Bll"
android:layout_weight="25"
android:background="#drawable/button_purple"
android:textColor="#ffffff"
android:onClick="actionLong"
/>
<Button android:id="#+id/button_tous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Blt"
android:layout_weight="25"
android:background="#drawable/button_purple"
android:textColor="#ffffff"
android:onClick="actionTous"
android:state_pressed="true"
/>
</LinearLayout>
<Button android:id="#+id/button_orig"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Bo"
android:background="#drawable/button_purple"
android:textColor="#ffffff"
android:onClick="actionOrigine"
/>
</LinearLayout>
<!-- /invisible -->
<Button android:id="#+id/button_recher"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Br"
android:background="#drawable/button_green"
android:textColor="#ffffff"
android:onClick="actionRecherche"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Thanks in advance.
If I understand correctly you want to use android:visibility="gone" so that what ever you set to "gone" does not occupy any space on the layout.
Basically, instead of android:visibility="invisible" you should use android:visibility="gone"
See if that works.
Related
I am trying to set two or more buttons side by side at the bottom of the screen, I do know that in LinearLayout you can set buttons side by side by using android:layout_weight
and i know that I can set the buttons at the bottom of the screen by using relative layout, but I cant seem to do both at the same time for the same buttons! is that possible?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:background="#0B333F"
android:fillViewport="true"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
...
...
...
...
...
...
...
...
...
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<!-- <LinearLayout -->
<!-- android:layout_width="fill_parent" -->
<!-- android:layout_height="wrap_content" -->
<!-- android:layout_alignParentBottom="true" -->
<!-- android:layout_marginTop="5dp" -->
<!-- android:paddingLeft="5dp" -->
<!-- android:paddingRight="5dp" > -->
<!-- android:layout_weight="1" -->
<Button
android:id="#+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#F0BF00"
android:text="#string/save"
android:textColor="#FFF"
android:textStyle="bold" />
<Button
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#F0BF00"
android:text="#string/cancel"
android:textColor="#FFF"
android:textStyle="bold" />
<!-- </LinearLayout> -->
</RelativeLayout>
</LinearLayout>
</ScrollView>
As you can see in the commented part, I did try both but cant seem to get it to work! Please help.
FYI
I don't want a sticky menu; in small screens there will be a scroll so this will not affect small screens since it is already at he bottom, but big screens that will not need to scroll I want the buttons at the bottom
If you need to your view at bottom you have to just set
android:gravity="bottom"
to your LinearLayout.
UPDATE:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:background="#0B333F"
android:fillViewport="true"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<!-- <LinearLayout -->
<!-- android:layout_width="fill_parent" -->
<!-- android:layout_height="wrap_content" -->
<!-- android:layout_alignParentBottom="true" -->
<!-- android:layout_marginTop="5dp" -->
<!-- android:paddingLeft="5dp" -->
<!-- android:paddingRight="5dp" > -->
<!-- android:layout_weight="1" -->
<Button
android:id="#+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#F0BF00"
android:text="#string/save"
android:textColor="#FFF"
android:textStyle="bold" />
<Button
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#F0BF00"
android:text="#string/cancel"
android:textColor="#FFF"
android:textStyle="bold" />
<!-- </LinearLayout> -->
</RelativeLayout>
</LinearLayout>
</ScrollView>
You can do that like below:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#F0BF00"
android:text="save"
android:textColor="#FFF"
android:textStyle="bold" />
<Button
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#F0BF00"
android:text="cancel"
android:textColor="#FFF"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
If you want your buttons to always be visible on the screen and your buttons centered at the bottom, move your ScrollView like in the following. If you want your buttons to fill the bottom line or be placed relative to the edges, then the bottom LinearLayout can be removed and a couple of alignment attributes set on the buttons instead.
<?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:layout_marginTop="40dp"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:background="#0B333F"
android:fillViewport="true"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
.....
.....
.....
.....
.....
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal" >
<Button
android:id="#+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#F0BF00"
android:text="#string/save"
android:textColor="#FFF"
android:textStyle="bold" />
<Button
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#F0BF00"
android:text="#string/cancel"
android:textColor="#FFF"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
I think here are a good solution for you
<RelativeLayout >
<LinearLayout
android:id="#+id/bottomLayout"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button />
<Button />
</LinearLayout>
<ScrollView
android:layout_alignParentTop="true"
android:layout_above="#id/bottomLayout">
</ScrollView>
</RelativeLayout>
They are only nested layout structure so you need add more attribute that you want. Please let me know the result asap.
I Managed to do it by adding
android:gravity="bottom"
as PiYusH GuPtA suggested to the LinearLayout that contains the buttons, but I also needed to change that LinearLayout layout from
android:layout_height="wrap_content"
to
android:layout_height="fill_parent"
-
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
...
...
...
...
...
...
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:gravity="bottom" >
<Button
android:id="#+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="#F0BF00"
android:text="#string/save"
android:textColor="#FFF"
android:textStyle="bold" />
<Button
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#F0BF00"
android:text="#string/cancel"
android:textColor="#FFF"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
If you want the buttons always at the bottom of the content, not always visible on the screen, and to fill the bottom row of the screen, you can do the following.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:background="#0B333F"
android:fillViewport="true"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
........
........
........
........
........
........
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal" >
<Button
android:id="#+id/saveButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#F0BF00"
android:text="#string/save"
android:textColor="#FFF"
android:textStyle="bold" />
<Button
android:id="#+id/cancelButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:background="#F0BF00"
android:text="#string/cancel"
android:textColor="#FFF"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
I want to create a Layout that have the feature of expand and collapse .Expand should be like that at a time only one row can be expanded ,if user clicks on other first should be closed by itself.In each row i have to show different layout design .
Please help me in this ,i have searched but i am not getting i how could i create this functionality .Please take this as a reference how it will be like .Please suggest me the best approach to get this
You can use a lib Accordion-View screenshot is :
I have implemented some code as the answer suggested by #Super User. So from that i think you will sure get your solution.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:accordion="http://schemas.android.com/apk/res-auto/com.sentaca.android.accordion"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/main_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#ff0000"
android:orientation="horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Offline Booking Request"
android:textColor="#fff"
android:textStyle="bold" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<com.sentaca.android.accordion.widget.AccordionView
android:id="#+id/accordion_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
accordion:header_layout_fold_button_id="#id/foldButton"
accordion:header_layout_id="#layout/accordion_header"
accordion:header_layout_label_id="#id/foldText"
accordion:section_bottom="#layout/accordion_footer"
accordion:section_container="#layout/accordion_section"
accordion:section_container_parent="#id/section_content"
accordion:section_headers="#array/accordion_sections"
accordion:section_visibility="#array/accordion_visibility"
android:background="#fff5f5f5"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please specify offline car details if you need any cars of travels"
android:textSize="14sp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="45dp"
android:text="Plase click the checkbox to send the details"
android:textColor="#ff0000" />
<include layout="#layout/radio" >
</include>
</LinearLayout>
<LinearLayout
android:id="#+id/example_get_by_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item 2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item 3" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item 4" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item 4" />
</com.sentaca.android.accordion.widget.AccordionView>
</ScrollView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Review" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Confirm" />
</LinearLayout>
</LinearLayout>
Now just remember one thing whenever you want to add layout items then add item in Linear Layout and make different layout for different sections and after that include that layout in your Linear layout. I have tried for one section named radio.xml file which is included in Linear Layout above.
radio.xml
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:checked="true"
android:text="Domestic"
android:textColor="#ff0000" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="InterNational"
android:textColor="#ff0000" />
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Pick Up Location"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText1"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_weight="1"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="DropLocation"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText2"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_weight="1"
android:ems="10" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:text="Car Type"
android:textColor="#000" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_gravity="center"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:text="Remarks"
android:textColor="#000" />
<EditText
android:id="#+id/editText3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textMultiLine" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
You can start with ExpandableListView and customize it to your need. I think this would be a good way to start. Please follow a link below to customize ExpandableListView :
http://androidexample.com/Custom_Expandable_ListView_Tutorial_-_Android_Example/index.php?view=article_discription&aid=107&aaid=129
You can google for more links on customizing expandablelistview. Hope it helps.
You can use scaleAnimation where you can add in each section a layout panel and inside the layout textview or anything as your requirement. See this. Hope it might help you.
http://wwwpriyaandroid.blogspot.in/2013/10/accordion.html
I am trying to make a layout where the last button will always be at the bottom and will be able to scroll if needed. Here is what I have so far:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/gradient_bg" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<!-- Name Label -->
<TextView android:id="#+id/NameDesc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Spot Name:"
style="#style/black_text"/>
<!-- Input Name -->
<EditText android:id="#+id/inputName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:layout_marginBottom="15dip"
android:singleLine="true"
android:capitalize="words"/>
<!-- Button Create Product -->
<Button android:id="#+id/btnDate"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Set Date"
android:tag="3"
android:onClick="onClick"
android:visibility="gone"
style="#style/btnStyleBreakerBay"/>
<TextView
android:id="#+id/txtDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Date of Event:"
style="#style/black_text"
android:visibility="gone"/>
<Button android:id="#+id/btnTime"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Set Time"
android:tag="4"
android:onClick="onClick"
android:visibility="gone"
style="#style/btnStyleBreakerBay"/>
<TextView
android:id="#+id/txtTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Time of Event:"
style="#style/black_text"
android:visibility="gone"/>
<!--Type in info^ -->
<TextView
android:id="#+id/txtType"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Event Type:"
style="#style/black_text"
android:visibility="gone"
/>
<Spinner
android:id="#+id/spinner_event"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/event_arrays"
android:prompt="#string/event_prompt"
android:visibility="gone"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Pavement Type:"
style="#style/black_text"
/>
<Spinner
android:id="#+id/spinner_pavement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/pavement_arrays"
android:prompt="#string/pavement_prompt" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Amount of Traffic:"
style="#style/black_text"
/>
<Spinner
android:id="#+id/spinner_traffic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/traffic_arrays"
android:prompt="#string/traffic_prompt" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Environment Type:"
style="#style/black_text"
/>
<Spinner
android:id="#+id/spinner_enviro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/enviro_arrays"
android:prompt="#string/enviro_prompt" />
<Button
android:id="#+id/btnCapturePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take a Picture"
android:tag="1"
android:onClick="onClick"
style="#style/btnStyleBreakerBay"/>
<TextView
android:id="#+id/txtPreview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Image Preview:"
style="#style/black_text"
android:visibility="gone"/>
<!-- To display picture taken -->
<ImageView
android:id="#+id/imgPreview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<FrameLayout
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
</FrameLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<!-- Button Create Product -->
<Button android:id="#+id/btnCreate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Create Spot"
android:tag="2"
android:onClick="onClick"
style="#style/btnStyleBreakerBay"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
But I cannot get the last button to go at the bottom. Could someone please help me? I have tried a couple answers on here but none seemed to work. Maybe it was because of how I set the height of the other layouts but I'm not too sure on that.
Thank you in advance,
Tyler
Look this my implementations in some projects i think it will help you to determine your layout ,
may help you and feel free to feed me back in any issue
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#FC9"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Fixed Header"
android:textColor="#000"
android:textSize="20sp" />
</RelativeLayout>
<!-- Footer aligned to bottom -->
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#FC0"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Fixed Footer"
android:textColor="#000"
android:textSize="20sp" />
</RelativeLayout>
<ScrollView
android:id="#+id/scrollableContents"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/footer"
android:layout_below="#id/header"
android:background="#005" >
</ScrollView>
</RelativeLayout>
I think the best way I can think of is to use RelativeLayout. It has the member android:layout_alignParentBottom="true" which you can use in your Button within the RelativeLayout. This will always keep it at bottommost.
The layout posted below creates the the UI. I currently get a result as shown in a.png and c.png (there is a lot of empty space), but I hope to achieve something similar to b.png and d.png. How can I do this?
I want the height of lvReceiver and lvOnlyOrExcept to increase and decrease automatically by the rows of data.
What I get now looks like this:
a.png
c.png
What I want it to look like:
b.png
d.png
The layout used is this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/border_ui" >
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="a15284e3e927f18"
ads:loadAdOnCreate="false" />
<LinearLayout
android:id="#+id/LinearLayoutName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/adView"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvRuleNameTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rule Name" />
<TextView
android:id="#+id/tvRuleName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Rule Name" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayoutChecked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayoutName"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvEnabledRule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enabled Rule" />
<CheckBox
android:id="#+id/chEnabledRule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:text="" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayoutOption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayoutChecked"
android:orientation="vertical" >
<TextView
android:id="#+id/tvReceiveTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Receive Number" />
<ListView
android:id="#+id/lvReceiver"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/tvOptionTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forward Option" />
<ListView
android:id="#+id/lvOnlyOrExcept"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center_vertical"
android:background="#DCDCDC"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/btnEdit"
style="#style/myTextAppearance"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:checked="true"
android:text="Edit" />
<Button
android:id="#+id/btnDelete"
style="#style/myTextAppearance"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Delete" />
<Button
android:id="#+id/btnClose"
style="#style/myTextAppearance"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Close" />
</LinearLayout>
</RelativeLayout>
The xml which you are inflating for the list views must be having excess padding/margin. Please post the xml which you are using to inflate for both the list views. The issue lies there
I am making an android application that uses these views:
(Root) - LinearLayout
(Child of root) - ListView + 3 other linearlayouts beneeth that listview. But once i add to many items to the listview, the layouts are being placed outside of the screen. Which i don't want to. How can i make this happen? So that all of the three linearlayouts stay on the screen, at the bottom??? Please help and thanks in advance!
My screen XML code:
<?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="fill_parent"
android:background="#drawable/background"
android:orientation="vertical" >
<TextView
android:id="#+id/NotesWelcomeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/NotesWelcomeText" />
<ListView
android:id="#+android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView
<LinearLayout
android:id="#+id/DeleteAllItemsFromListViewLinearLayout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" >
<Button
android:id="#+id/CancelButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Cancel" />
<Button
android:id="#+id/DeleteAllButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Delete" />
</LinearLayout>
<LinearLayout
android:id="#+id/DeleteItemFromListViewLinearLayout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" >
<Button
android:id="#+id/CancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Cancel" />
<Button
android:id="#+id/DeleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Delete" />
</LinearLayout>
<LinearLayout
android:id="#+id/AddItemToListViewLinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
<EditText
android:id="#+id/AddItemToListViewEditText"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
</EditText>
<Button
android:id="#+id/AddItemToListViewButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Add" />
</LinearLayout>
</LinearLayout>
Try this, you'll have to add the string references and background again, I removed them so I wouldn't have errors
<?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"
android:orientation="vertical">
<TextView android:id="#+id/NotesWelcomeTextView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="NotesWelcomeText" />
<ListView android:id="#+android:id/list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_above="#+id/AddItemToListViewLinearLayout"
android:layout_below="#+id/NotesWelcomeTextView">
</ListView>
<LinearLayout android:id="#+id/DeleteAllItemsFromListViewLinearLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:visibility="invisible"
android:layout_alignParentBottom="true">
<Button android:id="#+id/CancelButton2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Cancel" />
<Button android:id="#+id/DeleteAllButton" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Delete" />
</LinearLayout>
<LinearLayout android:id="#+id/DeleteItemFromListViewLinearLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:visibility="invisible"
android:layout_alignParentBottom="true">
<Button android:id="#+id/CancelButton" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Cancel" />
<Button android:id="#+id/DeleteButton" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Delete" />
</LinearLayout>
<LinearLayout android:id="#+id/AddItemToListViewLinearLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:visibility="gone" android:layout_alignParentBottom="true">
<EditText android:id="#+id/AddItemToListViewEditText"
android:layout_width="250dp" android:layout_height="wrap_content"
android:layout_weight="1">
</EditText>
<Button android:id="#+id/AddItemToListViewButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:text="Add" />
</LinearLayout>
Give your ListView a weight of 0 and set its height to 0. This will tell the ListView to only take up the space that is not use by other views.
<ListView ...
android:layout_weight="0"
android:layout_height="0"
...
/>