Formatting xml for buttons at bottm - android

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.

Related

Expand and Collapase in Android

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

Layout causing App to crash

so I have been trying to change the layout in a couple of my xmls but for some reason when I changed this one it crashes the app. The new layout looks like:
<?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"
android:background="#drawable/gradient_bg" >
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center" >
</RelativeLayout>
<!-- Footer aligned to bottom -->
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/ButtonOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_toLeftOf="#+id/ButtonAll"
android:text="Go"
style="#style/btnStyleBreakerBay"/>
<Button
android:id="#+id/ButtonAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="See All"
android:layout_toRightOf="#+id/ButtonOK"
android:layout_toLeftOf="#+id/ButtonBack"
style="#style/btnStyleBreakerBay"/>
<Button
android:id="#+id/ButtonBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Back"
android:layout_toRightOf="#+id/ButtonAll"
style="#style/btnStyleBreakerBay"/>
</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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView android:id="#+id/typeEvent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type of Event:"
android:visibility="gone"
style="#style/black_text"/>
<Spinner
android:id="#+id/spinner_search_event"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/event_search_arrays"
android:prompt="#string/event_prompt"
android:visibility="gone"
android:popupBackground="#31535c"/>
<!-- Name Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type of Pavement:"
style="#style/black_text"/>
<Spinner
android:id="#+id/spinner_search_pavement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/pave_search_arrays"
android:prompt="#string/pavement_prompt"
android:popupBackground="#31535c" />
<!-- Name Label -->
<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_search_traffic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/traffic_search_arrays"
android:prompt="#string/traffic_prompt"
android:popupBackground="#31535c"/>
<!-- Name Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type of Environment:"
style="#style/black_text"/>
<Spinner
android:id="#+id/spinner_search_enviro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/enviro_search_arrays"
android:prompt="#string/enviro_prompt"
android:popupBackground="#31535c"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Max Miles away from you:"
style="#style/black_text"/>
<Spinner
android:id="#+id/spinner_dist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/dist_arrays"
android:prompt="#string/dist_prompt"
android:popupBackground="#31535c"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Now the logcat says it is crashing because:
02-12 06:58:05.351: E/AndroidRuntime(2367): java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
And a couple more red lines but I think that is the main thing. Now I am guess that is has to do with how I have the buttons in #+id/footer so how could I fix this?
Thank you in advance,
Tyler
<Button
android:id="#+id/ButtonOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_toLeftOf="#+id/ButtonAll"
android:text="Go"
style="#style/btnStyleBreakerBay"/>
<Button
android:id="#+id/ButtonAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="See All"
android:layout_toRightOf="#+id/ButtonOK"
android:layout_toLeftOf="#+id/ButtonBack"
style="#style/btnStyleBreakerBay"/>
android:layout_toLeftOf="#+id/ButtonAll" and android:layout_toRightOf="#+id/ButtonOK" make a circular dependency.

Layout invisible, button up on him

(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.

Layout does not match preview

I have designed an action sheet that appears when a user press a button. It is a separate xml file that I am including in another layout file. In the layout preview, it looks exactly as I want it. However, when it runs on my phone, the layout is messed up.
Here is how it should look:
And here is how it does look:
Does anyone have any idea why this might be happening?
Here is the layout code for the action sheet. The section that isn't displaying right is in the last linear layout
<?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="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/sheet_header" >
<ImageButton
android:id="#+id/left_justified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/center_justified"
android:layout_toLeftOf="#+id/center_justified"
android:background="#android:color/transparent"
android:src="#drawable/alignment_left" />
<ImageButton
android:id="#+id/center_justified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:background="#android:color/transparent"
android:src="#drawable/alignment_center" />
<ImageButton
android:id="#+id/right_justified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/center_justified"
android:layout_toRightOf="#+id/center_justified"
android:background="#android:color/transparent"
android:src="#drawable/alignment_right" />
<ImageButton
android:id="#+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/center_justified"
android:background="#android:color/transparent"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/center_justified"
android:layout_marginRight="10dp"
android:src="#drawable/sheet_done_btn"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/sheet_background"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp" >
<TextView
android:id="#+id/font_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="Font"
android:textColor="#806014"
android:textSize="20sp" />
<TextView
android:id="#+id/size_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="Size"
android:textColor="#806014"
android:textSize="20sp" />
<TextView
android:id="#+id/color_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="Color"
android:textColor="#806014"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
And here is how it is included:
<FrameLayout
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/edit_text_frame">
<include layout="#layout/edit_text"/>
</FrameLayout>
Edit: In addition to a fix for this specific problem does anyone know why the preview doesnt match the way it actually shows up on the phone?
Thanks for the help!
<?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="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/sheet_header" >
<ImageButton
android:id="#+id/left_justified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/center_justified"
android:layout_toLeftOf="#+id/center_justified"
android:background="#android:color/transparent"
android:src="#drawable/alignment_left" />
<ImageButton
android:id="#+id/center_justified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:background="#android:color/transparent"
android:src="#drawable/alignment_center" />
<ImageButton
android:id="#+id/right_justified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/center_justified"
android:layout_toRightOf="#+id/center_justified"
android:background="#android:color/transparent"
android:src="#drawable/alignment_right" />
<ImageButton
android:id="#+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/center_justified"
android:background="#android:color/transparent"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/center_justified"
android:layout_marginRight="10dp"
android:src="#drawable/sheet_done_btn"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="#drawable/sheet_background"
android:orientation="vertical" >
<TextView
android:id="#+id/font_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Font"
android:textColor="#806014"
android:textSize="20sp" />
<TextView
android:id="#+id/size_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Size"
android:textColor="#806014"
android:textSize="20sp" />
<TextView
android:id="#+id/color_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Color"
android:textColor="#806014"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
You could place the font, size, color TextViews into a Table Layout.

Making linearlayouts stay at bottom of screen in android

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"
...
/>

Categories

Resources