Reputation:
Even though this problem has many solutions in stackoverflow, I could not solve my problem. I have two edit texts in the screen, one on top, another is attached to bottom of the screen. Whenever I click on bottom edit text, softkey board comes over it. I already played with windowSoftInputMode.
I dont want other content of the screen to scroll up when I click on my bottom edittext.
This is my xml layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@color/background"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/phone_number_edit_text_compose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_horizontal_margin"
android:layout_toLeftOf="@id/select_contact"
android:background="@drawable/phone_edittext_background_selector"
android:ems="10"
android:hint="@string/phone_edittext_hint"
android:inputType="phone"
android:paddingBottom="12dp"
android:paddingLeft="8dp"
android:paddingTop="12dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white" />
<ImageButton
android:id="@+id/selectcontact_compose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignBottom="@+id/phone_number_edit_text_compose"
android:layout_marginTop="@dimen/activity_horizontal_margin"
android:layout_toRightOf="@id/phone_number_edit_text_compose"
android:background="@drawable/select_contact_background_selector"
android:contentDescription="@string/select_contact_content_description"
android:src="@drawable/select_contact_selector"
android:layout_marginLeft="2dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"/>
<View
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="2px"
android:layout_below="@id/phone_number_edit_text_compose"
android:layout_marginTop="@dimen/redial_screen_distance_between_views"
android:background="@drawable/separator" />
<LinearLayout
android:id="@+id/repetition_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/view1"
android:clickable="true"
android:onClick="RepetitionLayoutClickListener"
android:orientation="horizontal"
android:paddingBottom="@dimen/redial_screen_distance_between_views"
android:paddingTop="@dimen/redial_screen_distance_between_views"
android:background="@drawable/repetition_layout_background_selector"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
<TextView
android:id="@+id/repetition_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/repetition"
android:textColor="@color/green"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Spinner
android:id="@+id/repetition_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:popupBackground="@color/dark_background" />
</LinearLayout>
<View
android:id="@+id/view2"
android:layout_width="wrap_content"
android:layout_height="2px"
android:layout_below="@id/repetition_layout"
android:background="@drawable/separator" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/view2"
android:orientation="horizontal"
android:paddingBottom="@dimen/redial_screen_distance_between_views"
android:paddingTop="@dimen/redial_screen_distance_between_views"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:id="@+id/date_layout">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/d"
android:textColor="@color/green"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/date_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/a"
android:paddingLeft="5dp"
android:textColor="@color/white"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<View
android:id="@+id/view3"
android:layout_width="wrap_content"
android:layout_height="2px"
android:layout_below="@id/date_layout"
android:background="@drawable/separator" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/view3"
android:orientation="horizontal"
android:paddingBottom="@dimen/redial_screen_distance_between_views"
android:paddingTop="@dimen/redial_screen_distance_between_views"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:id="@+id/time_layout">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/t"
android:textColor="@color/green"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/time_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/b"
android:paddingLeft="5dp"
android:textColor="@color/white"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/compose_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/compose_message_background"
android:hint="@string/compose_message_hint"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_toLeftOf="@+id/imageButton1" >
</EditText>
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/send_button_background"
android:src="@drawable/ic_action_send_now"
android:paddingRight="8dp"
android:paddingLeft="8dp"
android:layout_alignBottom="@+id/editText1"
android:layout_alignTop="@+id/editText1"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</LinearLayout>
And this my manifest xml.
<activity
android:name="com.task.SmsScreen"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"
>
</activity>
Upvotes: 5
Views: 21814
Reputation: 1
After two days of hassle and reading all the stackoverflow solutions I came up with my own. It worked for me. I had to use scrollview only then it adjusts itself in the tiny space by shrinking the view. Without scrollview I had to use the Outermost LinearLayout with layout_gravity:bottom. But with this settings all the elements drops at the bottom of the Screen. if used layout_margintop or layout_marginbottom then when keyboard pops up some of the textview or edittextview thrown away out of the screen .. Grrrrrrrrrrr....
So, finally I found this solution hope it may solve some of your problem.
in Manifest.xml
<activity
android:windowSoftInputMode="adjustResize"
android:screenOrientation="portrait"
android:configChanges="orientation">
In Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/love_bg_red_10"
android:gravity="center"
android:orientation="vertical"
tools:context="${packageName}.${activityClass}" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/txtvwYourName"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@layout/border_header"
android:gravity="center"
android:text="Your Name"
android:textColor="#FFF"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="@+id/edttxtFistName"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@layout/border_edittextview"
android:gravity="center"
android:hint="Type your name here"
android:includeFontPadding="false"
android:inputType="textPersonName"
android:lines="1"
android:maxLength="30"
android:tag="edttxtFistName"
android:textAllCaps="false"
android:textColor="#FFF"
android:textSize="20sp" />
<TextView
android:id="@+id/txtvwFavPersonName"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@layout/border_header"
android:gravity="center"
android:text="Name of your favorite person"
android:textColor="#FFF"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="@+id/edttxtLastName"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_marginBottom="35dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@layout/border_edittextview"
android:gravity="center"
android:hint="Type your favorite person's name"
android:inputType="textPersonName"
android:lines="1"
android:maxLength="30"
android:tag="edttxtLastName"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:id="@+id/btnCalculate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@layout/button_background"
android:text="Calculate"
android:textSize="20sp"
android:textStyle="bold" >
</Button>
</LinearLayout>
</ScrollView>
put a Linearlayout enclosing tag after scrollview.
Android really really awful .
Devcie: Xperia Z OS: JellyBean [ Dont know how it will behave in older versions.]
Upvotes: 0
Reputation: 1011
You did not say which version of android are you compiling for and which version are you running on. But check if you perhaps use fullscreen option set by about android:windowFullscreen attribute or by setting FLAG_FULSCREEN. This prevents adjusrResize option to wrok properly on newer APIs. It works for API 10 (2.3.5).
Upvotes: 4
Reputation: 6980
Remove your outer Linear Layout and place everything inside a Relative Layout. And align your bottom edit text to bottom of the layout by making alignParentBottom true. And main thing "Dont do anything to the android:windowSoftInputMode." Delete that line from manifest file. Let android take default.
Upvotes: 2
Reputation: 559
You should use
<activity
android:name="com.task.SmsScreen"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan"
>
</activity>
Upvotes: 0