auto grow edittext below buttons above keybord - android

Yet another same problem for android which drive developers crazy!
I want to make buttons above keyboard...
Here is my xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/home"
android:layout_width="910dp"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:keepScreenOn="true"
android:orientation="vertical"
android:padding="15dip" >
<com.custom.webview
android:id="#+id/webView1"
android:layout_width="900dp"
android:layout_height="350dp"
android:visibility="gone" >
</com.custom.webview>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:paddingBottom="5dip"
android:paddingTop="20dip"
android:text="#string/choose_the_outcome"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25sp" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:entries="#array/call_outcomes" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:paddingBottom="5dip"
android:paddingTop="20dip"
android:text="#string/notes"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25sp" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:fontFamily="sans-serif-light"
android:inputType="textMultiLine" >
</EditText>
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="25dip" >
<Button
android:id="#+id/button1"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:onClick="onCancel"
android:text="#android:string/cancel" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:onClick="onSave"
android:text="#string/save" />
</LinearLayout>
</LinearLayout>

just move all your layoouts as they are in the RelativeLayout. It might fix an issue.

Add this line
android:windowSoftInputMode="adjustResize|stateHidden"
to AndroidManifest.xml <activity> tag

You need to to do the following:
Just Make the text view child of a spinner
or put text view height = wrap_content.

Related

two edittext and one button on the same line

I have to place two edittext and a button on the same line.
The two edittext should have the same width, the largest possible so to fill the line. The button should be on the right.
It should be like this:
Edittext_______________________ EditText_________________________ Button
I post some relative code, which for the moment is not working.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="#+id/new_formulas"
>
<Button
android:textSize="30dp"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add"
android:id="#+id/add"
/>
<EditText
android:textSize="30dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="#string/add_hint"
android:id="#+id/add_hint2"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
/>
<EditText
android:textSize="30dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/add_hint"
android:id="#+id/add_hint"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/add"/></RelativeLayout>
Try following Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/button"
android:layout_alignParentLeft="true"
android:orientation="horizontal"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="User"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Pass"/>
</LinearLayout>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="Click"/>
</RelativeLayout>
Please try this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/new_formulas"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="#+id/add_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="100dp"
android:hint="Hint"
android:textSize="30dp" />
<EditText
android:id="#+id/add_hint2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/add_hint"
android:minWidth="100dp"
android:hint="hint2"
android:textSize="30dp" />
<Button
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/add_hint2"
android:text="Add"
android:textSize="30dp" />
</RelativeLayout>
Use Linear Layout :
<LinearLayout
android:id="#+id/new_formulas"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add"
android:textSize="30dp" />
<EditText
android:id="#+id/add_hint2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:hint="#string/add_hint"
android:textSize="30dp" />
<EditText
android:id="#+id/add_hint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/add_hint"
android:textSize="30dp" />
</LinearLayout>
Try this
<LinearLayout
android:id="#+id/new_formulas"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText
android:id="#+id/add_hint2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_weight="40"
android:gravity="center_horizontal"
android:hint="#string/add_hint"
android:textSize="30dp" />
<EditText
android:id="#+id/add_hint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/add"
android:layout_weight="40"
android:hint="#string/add_hint"
android:textSize="30dp" />
<Button
android:id="#+id/add"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20"
android:layout_alignParentRight="true"
android:text="#string/add"
android:textSize="30dp" />
</LinearLayout>
You can adjust weight acoording to your need but remember sum of all weight must be 100
You can achieve what you want using PercentRelativeLayout from the new Percent Support Library. It inherits all the alignment attributes of RelativeLayout and lets you specify dimensions and margins in percentages. Basically a counterpart of the layout_weight attribute of LinearLayout. Read Joanna Smith's #proTip for more info.
First add the dependency in app/build.gradle
dependencies {
...
compile 'com.android.support:percent:23.0.1'
}
Then change your code like this:
<android.support.percent.PercentRelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/new_formulas">
<Button
android:textSize="30dp"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/add" />
<EditText
android:textSize="30dp"
android:layout_toLeftOf="#id/add"
app:layout_widthPercent="40%"
android:layout_height="wrap_content"
android:id="#+id/add_hint" />
<EditText
android:textSize="30dp"
android:layout_toLeftOf="#id/add_hint"
app:layout_widthPercent="40%"
android:layout_height="wrap_content"
android:id="#+id/add_hint2" />
</android.support.percent.PercentRelativeLayout>
Some tips:
Use sp instead of dp for textSize
Always format the code (ctrl + alt + L) before posting. Makes it more readable.

Android Buttons not stretching to width of the screen

I'm using a bootstrap library for android which can be found here. Ive imported the library into my application but the problem im having is that the buttons do not span the entire screen width.
I've tried placing the buttons side by side and using android:layout_weight="1" but the button just moves to the left and does not stretch. I've even tried using android:layout_width="match_parent" but that increases the buttons height as well.
this is what happens if i set android:layout_width="0dip" and android:layout_weight="1" (for ok/cancel) and android:layout_width="match_parent"(for check button)
XML CODE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20sp" >
<TextView
android:id="#+id/textView1"
android:layout_width="318dp"
android:layout_height="wrap_content"
android:text="Send Pin To Email id."
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter Your Email Id Below"
android:textAppearance="?android:attr/textAppearanceMedium" />
<com.beardedhen.androidbootstrap.BootstrapEditText
android:id="#+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:ems="10"
android:hint="abc#example.com"
android:inputType="textEmailAddress"
bootstrapbutton:be_roundedCorners="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingBottom="15sp" >
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="#+id/OK"
style="#style/AppBaseTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:text="OK"
bootstrapbutton:bb_icon_left="fa-envelope"
bootstrapbutton:bb_roundedCorners="true"
bootstrapbutton:bb_size="medium"
bootstrapbutton:bb_type="default" />
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="#+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="CANCEL"
bootstrapbutton:bb_icon_left="fa-times"
bootstrapbutton:bb_roundedCorners="true"
bootstrapbutton:bb_size="medium"
bootstrapbutton:bb_type="default" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="15sp"
android:text="Got your Pin?Enter it below."
android:textAppearance="?android:attr/textAppearanceMedium" />
<com.beardedhen.androidbootstrap.BootstrapEditText
android:id="#+id/et_pin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:ems="10"
android:hint="XXXX"
android:inputType="number"
bootstrapbutton:be_roundedCorners="true" />
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="#+id/b_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="Check"
bootstrapbutton:bb_icon_left="fa-check"
bootstrapbutton:bb_roundedCorners="true"
bootstrapbutton:bb_size="medium"
bootstrapbutton:bb_type="default" />
</LinearLayout>
You need to use width as 0dip instead of wrap_content if you use weight property.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingBottom="15sp"
android:weightSum="2">
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="#+id/OK"
style="#style/AppBaseTheme"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:text="OK"
bootstrapbutton:bb_icon_left="fa-envelope"
bootstrapbutton:bb_roundedCorners="true"
bootstrapbutton:bb_size="medium"
bootstrapbutton:bb_type="default"
android:layout_weight="1"/>
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="#+id/cancel"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="CANCEL"
bootstrapbutton:bb_icon_left="fa-times"
bootstrapbutton:bb_roundedCorners="true"
bootstrapbutton:bb_size="medium"
bootstrapbutton:bb_type="default"
android:layout_weight="1"/>
And for single button, just use width as "match_parent"
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="#+id/b_check"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="Check"
bootstrapbutton:bb_icon_left="fa-check"
bootstrapbutton:bb_roundedCorners="true"
bootstrapbutton:bb_size="medium"
bootstrapbutton:bb_type="default" />
Hope this helps.

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

moving button bar

I have an activity that allows me to enter content. It consists of edit text and button bar. Whenever I what to input something to the edit text, a keyboard pops up and the button bar is on top if it so I can't see what I'm typing if the content is long(it goes behind the button bar). How can i fix it ?
my code is:
<RelativeLayout
android:id="#+id/toplayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/notetop"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingTop="5dp" >
<TextView
android:id="#+id/title_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="18sp" />
<EditText
android:id="#+id/etTitleJoke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/title_text1"
android:background="#android:color/transparent"
android:hint="#string/no_title"
android:imeOptions="actionNext"
android:singleLine="true"
android:textColor="#000000"
android:textSize="18sp" >
</EditText>
</RelativeLayout>
<view
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/etContentJoke"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toplayout"
class="ie.myjokes.LineEditText"
android:background="#android:color/transparent"
android:capitalize="sentences"
android:scrollHorizontally="true"
android:fadingEdge="vertical"
android:gravity="top"
android:padding="5dp"
android:scrollbars="vertical"
android:textColor="#000000"
android:textSize="22sp" >
<requestFocus />
</view>
<LinearLayout
android:id="#+id/footer"
style="#android:style/ButtonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:id="#+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClickSave"
android:text="#string/btn_save"
android:textColor="#000000" />
<Button
android:id="#+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClickCancel"
android:text="#string/btn_cancel"
android:textColor="#000000" />
</LinearLayout>
nevermind, I added this line into my activity and its gone now. Thank you
android:windowSoftInputMode="adjustPan"

Layout gets adjusted when keyboard shows

In my layout I have an admob ad showing with an EditText in the layout. When I focus in the edit text to type something the keyboard appears and moves the admob ad over the edittext and you cant see what you are typing in.
this is my layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="false" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/wood_floor" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.tyczj.bowling.adapters.RobotoThinTextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="30dp"
android:text="Add Bowler"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#33b5e5"
android:textSize="40dp" />
<FrameLayout
android:id="#+id/line"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView2"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="8dp"
android:background="#drawable/ab_solid_custom_blue_inverse_holo" >
</FrameLayout>
<com.tyczj.bowling.adapters.RobotoThinTextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/line"
android:layout_below="#+id/line"
android:layout_marginTop="20dp"
android:text="#string/bNameTV"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView1"
android:layout_below="#+id/line"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:layout_toRightOf="#+id/textView1"
android:inputType="textCapSentences" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView3"
android:layout_below="#+id/editText1"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:layout_toRightOf="#+id/textView3"
android:inputType="textCapSentences" >
<requestFocus />
</EditText>
<com.tyczj.bowling.adapters.RobotoThinTextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/line"
android:layout_below="#+id/textView1"
android:layout_marginTop="20dp"
android:text="#string/lNameTV"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_below="#+id/textView3"
android:layout_marginTop="15dp"
android:checked="true"
android:text="Right Handed" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/line"
android:layout_below="#+id/radioButton1"
android:text="Left Handed" />
<Button
android:id="#+id/done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/line"
android:layout_alignParentBottom="true"
android:layout_below="#+id/radioButton2"
android:onClick="onDoneClick"
android:text="#string/done" />
</RelativeLayout>
</ScrollView>
<com.google.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="IAB_BANNER"
ads:loadAdOnCreate="true" />
</RelativeLayout>
in my manifest I set android:windowSoftInputMode="stateVisible|adjustResize" in the activity but that didnt have any effect
How can I stop the ad from moving when the keyboard appears?
Have you tried the mode adjustPan? That may work better for you. Since you have a RelativeLayout with an element aligned to the bottom of the screen, an adjustResize will always keep that element at the bottom of the screen. You may be able to play with your layout to fix things by laying the ad out as being below the scrollview, rather than aligning to bottom.
Try using a LinearLayout instead of outmost RelativeLayout and add the ScrollView with android:layout_weight="1" and the AdView with android:layout_weight="0":
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0"
android:layout_weight="1"
...
/>
...
</ScrollView>
<com.google.ads.AdView
android:layout_width="fill_parent"
android:layout_height="0"
android:layout_weight="0"
.../>
</LinearLayout>

Categories

Resources