How to scroll in android LinearLayout? - android

Hi i have an application, where i want to use scroll option in liner layout. Please help me i am stuck.
<?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="fill_parent"
android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
>
<AnalogClock android:id="#+id/clock1" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageButton android:id="#+id/rssbtn" android:src="#drawable/rss"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ProgressBar android:id="#+id/progress"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<RadioGroup android:id="#+id/widget1" android:layout_width="wrap_content"
android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<RadioButton android:id="#+id/widget2"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Plain" android:checked="false" android:layout_gravity="left"
android:layout_weight="0">
</RadioButton>
<RadioButton android:id="#+id/widget3"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Serif" android:checked="true" android:layout_gravity="left"
android:layout_weight="0" android:typeface="serif">
</RadioButton>
<RadioButton android:id="#+id/widget25"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Bold" android:checked="false" android:layout_weight="0"
android:layout_gravity="left" android:textStyle="bold">
</RadioButton>
</RadioGroup>
<Spinner android:id="#+id/widget1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:drawSelectorOnTop="false" />
<TimePicker android:id="#+id/widget3" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox android:id="#+id/plain_cb" android:text="Plain"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<CheckBox android:id="#+id/serif_cb" android:text="Serif"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:typeface="serif" />
<CheckBox android:id="#+id/bold_cb" android:text="Bold"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textStyle="bold" />
<CheckBox android:id="#+id/italic_cb" android:text="Italic"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textStyle="italic" />
<Button android:id="#+id/button1" android:text="Label"
android:layout_width="fill_parent" android:layout_height="fill_parent" />
<Button android:id="#+id/button2" android:text="Label"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:typeface="serif" />
<Button android:id="#+id/button3" android:text="Label"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:textStyle="italic" />
<DatePicker android:id="#+id/datepicker"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<EditText android:id="#+id/edittext1" android:text="EditText 1"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<EditText android:id="#+id/button2" android:text="(206)555-1212"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:typeface="serif" android:phoneNumber="true" />
<EditText android:id="#+id/password" android:text="SuperSecret"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textStyle="bold" android:password="true" />
</LinearLayout>

Wrap your LinearLayout in a ScrollView at the top of the file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="fill_parent">
<LinearLayout
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
>
.....
</LinearLayout>
</ScrollView>

Related

button disappears in a horizontal orientation

Hello I have LinearLayout in ScrollView
In this LinearLayout I have some checkbox and
button at the bottom.
In vertical view it's ok but in horizontal view
the button disappear.
You can see this situation on screen shots:
vertical view
horizontal view
Of course srclolling down doesnt help
This is my xml
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:layout_marginLeft="10dp"
>
<CheckBox android:id="#+id/hotele"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hotele"
android:textSize="18sp"
android:layout_margin="5dp"
android:checked="true"
/>
<!-- more checkboxs... -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:id="#+id/gotowe"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="#color/colorPrimary"
android:padding="5dp"
android:text="Gotowe"
android:textColor="#fff"
android:textSize="16sp"
android:layout_centerInParent="true"
android:textAllCaps="false"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
Try to set the
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
to be with layout_height="wrap_content" . This will let you scroll to the end of the content.
I'm not sure what your looking for but may this help you
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="80dp"
android:weightSum="10">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginBottom="10dp"
android:layout_weight="9.5">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<CheckBox
android:id="#+id/hotele"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp" />
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight=".5">
<Button
android:id="#+id/gotowe"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:background="#color/colorPrimary"
android:padding="5dp"
android:text="Gotowe"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="80dp"
android:layout_marginLeft="10dp"
>
<CheckBox android:id="#+id/hotele"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hotele"
android:textSize="18sp"
android:layout_margin="5dp"
android:checked="true"
/>
<!-- more checkboxs... -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
</RelativeLayout>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/gotowe"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="#color/colorPrimary"
android:padding="5dp"
android:text="Gotowe"
android:textColor="#fff"
android:textSize="16sp"
android:layout_centerInParent="true"
android:textAllCaps="false"/>
</RelativeLayout>
Try this
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="80dp"
android:layout_marginLeft="10dp"
>
<CheckBox android:id="#+id/hotele"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hotele"
android:textSize="18sp"
android:layout_margin="5dp"
android:checked="true"
/>
<!-- more checkboxs... -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:id="#+id/gotowe"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="#color/colorPrimary"
android:padding="5dp"
android:text="Gotowe"
android:textColor="#fff"
android:textSize="16sp"
android:layout_centerInParent="true"
android:textAllCaps="false"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
Try this code : The list of checkbox will be scrollable and the button will be shown in two cases :
(As for the margin is up to you to choose the values of your margins)
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#+id/scrollable_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/gotowe"
android:layout_marginLeft="10dp"
android:layout_marginTop="80dp"
android:isScrollContainer="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<CheckBox
android:id="#+id/hotele"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:text="Hotele"
android:textSize="18sp"
/>
<!-- more checkboxs... -->
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/gotowe"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:layout_marginTop="30dp"
android:background="#color/colorPrimary"
android:padding="5dp"
android:text="Gotowe"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="16sp"/>
</RelativeLayout>
Just a minor change from your current xml file.
Try changing the margins of your inner Linearlayout to padding.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="80dp"
android:paddingLeft="10dp"
>
I was able to make it work this way.

how to allow only one radiobtton to be executed in a radiogroup inside a linear layout?

I am trying to place a radio group with 3 radio buttons inside a linear layout. My aim is to choose only one RadioButton inside the RadioGroup but, it is giving me an error that there are multiple root tags. Can someone figure out how to solve this?
file.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ok"
android:id="#+id/textemail"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioGroup>
<TextView
android:id="#+id/textView1"
android:layout_below="#+id/textemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To:"
/>
<TextView
android:id="#+id/TextTo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="khushi"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comment:"
/>
<TextView
android:id="#+id/TextS3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="your comment"
/>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="email us "
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="textMultiLine"
android:lines="10" />
<Button
android:id="#+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Send"
android:textStyle="italic"/>
</LinearLayout>
You immediately close your radiogroup:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"/>
This should be:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"> // Note that there is no forward slash at the end
And you are not closing the RadioGroup:
</RadioButton> <-- This should be </RadioGroup>
Your RadioButton (views) should be children of the RadioGroup(view). By closing your RadioGroup using /> you declare the RadioButton(s) and the RadioGroup as children of the LinearLayout.
The Following should work.
<?xml version="1.0" encoding="utf-8"?>
<Linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello"
android:id="#+id/textview"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioButton>
</RadioGroup>
<TextView
android:id="#+id/textViewllol"
android:layout_below="#+id/textemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hi:"
/>
<TextView
android:id="#+id/Texme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="comment:"
/>
<TextView
android:id="#+id/Text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="your comments"
/>
<TextView
android:id="#+id/textView45"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok"
/>
<EditText
android:id="#+id/editTextMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:lines="10" />
<Button
android:id="#+id/button4785"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="send"
/>
</LinearLayout>
Change below -
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"/>
to
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioGroup>
One of your Text is not in correct format change it as below -
<TextView
android:id="#+id/textView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok:"
/>
to
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok:"
/>
One more error -
change below -
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
to
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
You have one </Radiobutton> tag above </Radiogroup> that shouldn't be here. Just remove it to have :
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioGroup>

Scrollview issue in xml, doesn't work

I have a following code.. I want to scroll my text area and my buttons within in LinearLayout. But my bottom button which is in relativelayout i want to stay it always in bottom not scroll able.
Thanks
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="175dip"
android:background="#android:color/white">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="20dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:textSize="15dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="55dp"
android:textSize="15dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="75dp"
android:textSize="15dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="95dp"
android:textSize="15dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="115dp"
android:textSize="15dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="135dp"
android:textSize="15dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="155dp"
android:textSize="15dip"
/>
</RelativeLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Contact Us"/>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="#android:color/black"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/buttonCheck"
android:layout_width="50sp"
android:layout_height="50sp"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:background="#drawable/round_button"
android:text="Checked" />
</RelativeLayout>
</RelativeLayout>
As you are using relative layout, first put the button at the bottom of screen, and then let scrollview occupy the the height available.
Try following code:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/rel_btn_Check"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:background="#android:color/black" >
<Button
android:id="#+id/buttonCheck"
android:layout_width="50sp"
android:layout_height="50sp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/round_button"
android:text="Checked" />
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/rel_btn_Check"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="175dip"
android:background="#android:color/white" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="20dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:textSize="15dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="55dp"
android:textSize="15dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="75dp"
android:textSize="15dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="95dp"
android:textSize="15dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="115dp"
android:textSize="15dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="135dp"
android:textSize="15dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="155dp"
android:textSize="15dip" />
</RelativeLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="XYZ" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Contact Us" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
</RelativeLayout>
use this mechanism
set scroll view >
android:layout_weight="1"
and put footer :
android:layout_alignParentBottom="true"
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical">
<ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1">
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="jgfhrtuioghju oioupotyuhjipouipoi typ[ipo[ip[ijup0[ip0[ujiptjuip[juip[i]]]]]]] jogi5thjuohuortthjuo90uto okithjoitthjuo thjpo ktjhporyjohj ptlhjyjohjpy plthjoyjpokjotjhojuyojuhoithjoi kgjhoithoithjuotjupojutpo[ujotpotpojuote]ihihoihoi rguigreuighreiuyghir orighoihyheiyhreiygh oighoihtgihidrfyh8irfyhuesghuyhuiehvguyh rueighuyghuiyghieryhirgeyhi gorfihoihklrjegoij5oi hi thkoihioghoirhirhuiurg] th5yj u trjuykyu yjytku yktyu k ykj k y jiyku ykj yuk yku k y 6ty 6y 6yy kuiil 6 u67 uokityy7 i78o8 "/>
</ScrollView>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"><Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="rgfjughtih g5yujhoihuoi"/></LinearLayout></LinearLayout>

Trouble getting relative layout right

I have been pulling my hair out trying to get my relative layout setup the way I want. I want to have a EditText on the left with a TextView in the middle and a Button to the right and all those over a ListView Here is as close as I can get ...
Here is the xml I am using:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/new_bookmark_clock"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="12sp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/btn_add_new_bookmark"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/add" />
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/new_bookmark_name" />
</RelativeLayout>
Can anyone help me out?
You can better achieve it through LinearLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/new_bookmark_clock"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/btn_add_new_bookmark"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/add" />
</LinearLayout>
Try this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/new_bookmark_clock"
android:layout_alignBaseline="#+id/btn_add_new_bookmark"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="wrap_content"
android:layout_alignBaseline="#+id/btn_add_new_bookmark"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/btn_add_new_bookmark"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/add" />
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/new_bookmark_name" />
</RelativeLayout>
you can use this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.5"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.3"
android:text="XXXXXXXXX" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.2"
android:text="Add" />
</LinearLayout>
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/new_bookmark_name" />
</LinearLayout>
Try with below
change android:layout_width="12sp" to android:layout_width="wrap_content"
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/new_bookmark_clock"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/btn_add_new_bookmark"
android:text="xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="add" />
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/new_bookmark_name" />
</RelativeLayout>
The problem that you were providing fixed width to Textview which create problem, I just added one more Relative Layout which achieve your goal, have a look below code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_toRightOf="#+id/new_bookmark_name"
android:gravity="center"
android:text="xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_centerInParent=""
android:text="add" />
</RelativeLayout>
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/layout" />
</RelativeLayout>
try this one:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/add" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/new_bookmark_name" />
</LinearLayout>
</LinearLayout>
you can try it like this , this way it keeps your top_bar seperate from list view . Also for textview never use dp . Sp is used for text size.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id ="#+id/top_bar">
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/new_bookmark_clock"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="12sp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/btn_add_new_bookmark"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/add" />
</RelativeLayout
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

Android Emulator doesn't Scroll down

I am creating a layout as follows and when I emulate it in the AVD. It doesn't Scroll down to see the conten below the fold.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView android:text="#string/UserFormWelcome"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:textSize="20px" android:gravity="center" />
<TextView android:text="#string/name" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:textStyle="bold"
android:paddingTop="20px" android:paddingLeft="10px" />
<TableLayout android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TableRow android:layout_height="wrap_content"
android:layout_width="match_parent" android:paddingTop="20px">
<TextView android:text="#string/firstname"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:width="100px" android:paddingLeft="10px" />
<EditText android:id="#+id/LastName" android:width="200px"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
</TableRow>
<TableRow android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView android:text="#string/lastname"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:paddingLeft="10px" />
<EditText android:id="#+id/LastName" android:width="200px"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
<TextView android:text="#string/dob" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textStyle="bold"
android:paddingTop="20px" android:paddingLeft="10px" />
<TableLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:stretchColumns="3"
android:paddingTop="20px" android:paddingLeft="10px">
<TableRow>
<TextView android:text="#string/date" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_column="0" />
<TextView android:text="#string/month" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_column="1" />
<TextView android:text="#string/year" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_column="2" />
</TableRow>
<TableRow>
<Spinner android:id="#+id/spinnerDate" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_column="0" />
<Spinner android:id="#+id/spinnerMonth" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_column="1" />
<Spinner android:id="#+id/spinnerYear" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_column="2" />
</TableRow>
</TableLayout>
<LinearLayout android:id="#+id/linearLayout1"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:paddingLeft="10px">
<TextView android:text="#string/sex" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textStyle="bold"
android:paddingTop="20px" />
<RadioGroup android:id="#+id/radioGroup1"
android:orientation="horizontal" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton android:text="Male" android:id="#+id/rdbMale"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:paddingRight="20px" android:checked="true" />
<RadioButton android:text="Female" android:id="#+id/rdbFemale"
android:layout_height="wrap_content" android:layout_width="wrap_content" />
</RadioGroup>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:paddingLeft="10px">
<TextView android:text="#string/city" android:id="#+id/textView3"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textStyle="bold" android:paddingTop="20px"
android:paddingBottom="10px" />
<Spinner android:id="#+id/citySpiner" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Spinner>
</LinearLayout>
</LinearLayout>
You should wrap your layout / the part you want to scoll into a ScrollView.
e.g. you can rewrite your layout as:
<?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">
<LinearLayout android:orientation="vertical"
android:layout_height="wrap_content" android:layout_width="wrap_content">
<TextView [...]
[...]
</LinearLayout>
</ScrollView>
so your root tag will be a ScrollView, and you just paste your current layout inside.
you just need to remove the namespace declaration from your LinearLayout, and declare it in the ScrollView.
The ScrollView API Docs might be helpful, and of course, Romain Guy's "ScrollView's Handy tricks".

Categories

Resources