I do set resize in my manifest so the screen does move up when I tap on the EditText, however It looks like this:
And I would like it to look like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white_three"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/enter_bio"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="130dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="5dp">
<EditText
android:id="#+id/user_biography"
android:layout_width="match_parent"
android:layout_height="100dp"
android:hint="#string/biography_placeholder"
android:textAppearance="#style/TextAppearance.Font.Volkswagen"
android:textColor="#color/black_87"
android:textSize="16sp"
android:maxLength="160"
android:imeOptions="actionDone|flagNoFullscreen"
android:inputType="textAutoCorrect|textCapSentences"
/>
<TextView
android:id="#+id/user_biography_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="18dp"
android:paddingBottom="5dp"
android:textAppearance="#style/TextAppearance.Font.Volkswagen"
android:textColor="#color/black_87"
android:textSize="14sp"
tools:text="60" />
</RelativeLayout>
</LinearLayout>
enter_bio is the element I would like the keyboard to appear under
put the entire view inside a ScrollView and set the android:windowSoftInputMode = adjustPan it will do the trick.
you just need to add this piece of code.
or
Try this
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE |WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
However, instead of doing this at runtime, you can set it in the manifest as an Activity (parent) attribute. This will also be handled in your fragment (child):
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
Related
I'm trying to make a layout aware whether the softkeyboard is visible or not since it covers part of the UI. Moving the UI up when the keyboard comes up and making it scrollable would be preferable.
Is this possible to do, and if so, how?
Image of view without keyboard:
nokeyboard
Image of view with keyboard:
with keyboard
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="#dimen/dialog_min_width"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_l"
android:background="#color/white"
android:minWidth="#dimen/dialog_min_width"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:nestedScrollingEnabled="false">
<LinearLayout
android:id="#+id/dialog_content"
style="#style/DialogContent">
<TextView
android:id="#+id/dialog_title"
style="#style/DialogTitle"
android:text="#string/label_start_round"
/>
<TextView
style="#style/InputLabel"
android:text="#string/label_player_name"
/>
<EditText
android:id="#+id/player_name"
style="#style/Widget.AppCompat.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textAutoCorrect"
/>
<TextView
style="#style/InputLabel"
android:text="#string/label_player_handicap"
/>
<EditText
android:id="#+id/player_handicap"
style="#style/Widget.AppCompat.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
/>
<TextView
style="#style/InputLabel"
android:text="#string/label_gender"
/>
<Spinner
android:id="#+id/spinner_gender"
style="#style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
style="#style/InputLabel"
android:text="#string/label_selected_tee"
/>
<Spinner
android:id="#+id/player_tee"
style="#style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/dialog_footer"
style="#style/DialogFooter">
<TextView
android:id="#+id/button_cancel"
style="#style/DialogButton"
android:text="#string/label_cancel"
/>
<TextView
android:id="#+id/button_start"
style="#style/DialogButton"
android:text="#string/label_start"
/>
</LinearLayout>
</LinearLayout>
You need to look at the android:windowSoftInputMode setting in your manifest.
The adjustment made to the activity's main window — whether it is
resized smaller to make room for the soft keyboard or whether its
contents pan to make the current focus visible when part of the window
is covered by the soft keyboard.
The android:windowSoftInputMode did not work for me since I was using a LinearLayout (overlapping the RelativeLayout in the background, however this wasn't show in the question). What I had to do was:
Change the outermost LinearLayout to a RelativeLayout
Put both inner LinearLayouts within the ScrollView (and make the lower LinearLayout a RelativeLayout to fix some layout issues related to the move)
Add getDialog().getWindow().setSoftInputMode((WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)); to the fragments onCreateView
The manifest could remain unchanged using this solution.
I am showing and hiding views on a particular actions using some animation, I used LayoutTransition and it seems to work fine except one thing, while the animation is going, the background of some TextViews changes and reset to the default white background!!
Following is the code I am using to apply animation after hide/show.
mRightTransitioner = new LayoutTransition();
mRightTransitioner.setDuration(1000);
vg_rightContainer.setLayoutTransition(mRightTransitioner);
Edited: even without animation i tried, same problem, the background resets once view's position changes
Edited: here how i declared the views in the XML
<LinearLayout
android:id="#+id/ll_req_reasonwrapper"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:baselineAligned="false"
android:gravity="right"
android:orientation="horizontal"
android:visibility="gone" >
<EditText
android:id="#+id/et_req_reasons"
android:layout_width="400dp"
android:layout_height="match_parent"
android:background="#drawable/comments_textbox"
android:gravity="right|center_vertical"
android:inputType="text"
android:paddingRight="8dp" />
<TextView
android:layout_width="100dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="#string/str_req_preasons" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_req_timewrapper"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:baselineAligned="false"
android:gravity="right"
android:orientation="horizontal"
android:visibility="gone" >
<LinearLayout
android:id="#+id/ll_req_endtimewrapper"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:id="#+id/ftv_req_endtime"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#drawable/comments_textbox"
android:freezesText="true"
android:gravity="right|center_vertical"
android:inputType="numberDecimal"
android:paddingRight="8dp" />
<TextView
android:layout_width="100dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="#string/str_req_endtime" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_req_starttimewrapper"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="50dp" >
<TextView
android:id="#+id/ftv_req_starttime"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#drawable/comments_textbox"
android:freezesText="true"
android:gravity="right|center_vertical"
android:inputType="numberDecimal"
android:paddingRight="8dp" />
<TextView
android:layout_width="100dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="#string/str_req_starttime" />
</LinearLayout>
</LinearLayout>
for instance: if i hide 'll_req_reasonwrapper', then the LinearLayout 'll_req_timewrapper' moves up, then the backgrounds of the textViews like 'ftv_req_starttime' becomes white!!
Please help.
Edited Answer:
if your are using linear layout then if the child is not being displayed, it is not going to be laid out and not going to be the part of the measurements ( as it looks like ). I recommend to use the RelativeLayout.
You can try
android:background="#null"
for your buttons. if your are using some custom class for button then add
.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
for this specific views.
Need more code. The fact that disabling the LayoutTransition does not solve your issue, means that the animation is not the issue.
How do you reinstantiate child views or populate your view. Are you removing views with setVisibility(View.GONE) and then setting them back with setVisibility(View.VISIBLE)
OR
Are you removing childAt(i) and then dynamically adding custom views
I'm sorry I couldnt add a comment since I dont have the reputation for that but I think I am able to answer your question if you post more code.
I'm trying to add a footer containing an imagebutton, an textview and another imagebutton to my activity (I want to make an app like whatsapp and it should nearly look the same). I have tried many ways, but all didnt work.
I tried to make a footer like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/chatBottom"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:background="#D8D8D8"
android:layout_alignParentBottom="true" >
<ImageButton
android:id="#+id/emojiButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:src="#drawable/emoji_button"
android:background="#D8D8D8"
android:padding="10dp"
android:contentDescription="#string/empty"/>
<EditText
android:id="#+id/enterMessage"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:padding="5dp"
android:layout_toLeftOf="#+id/sendMessage"
android:layout_toRightOf="#id/emojiButton"
android:background="#drawable/textfield_multiline_activated_holo_dark"
android:hint="" />
<ImageButton
android:id="#+id/sendMessage"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#D8D8D8"
android:contentDescription="#string/empty"
android:padding="10dp"
android:src="#drawable/action_send_message" />
and add it using include in xml or via addView() in java, but nothing worked properly. Most important is that the footer has its on background colour (always when I tried to set a colour to the layout where the footer is in, the whole activity got this colour) and that the textview resizes automatically.
Best regards, Oliver
When I click in my edit text and my keyboard shows up, everything seems to be ok as in the picture bellow:
But when it has to shrink a little bit more my image is resized extending a invisible area, and my TextView still as big as in the begining, then my layout doesn't work anymore:
I've tried to create new images and dimensions for xhdpi resolution, but it didn't any effect
How can I fix it? How can I resize everything proportionaly. (I've tried to put a scrollview but i have a ListView inside my layout, as you can see in the code below)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/login_background"
android:descendantFocusability="beforeDescendants"
android:clickable="true"
android:focusableInTouchMode="true"
tools:context=".LoginActivity"
android:id="#+id/fundoLogin" >
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<ImageView
android:id="#+id/image_login_fields"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/image_logo"
android:layout_centerHorizontal="true"
android:contentDescription="#string/img_login_fields_desc"
android:src="#drawable/login_fields">
</ImageView>
<ImageView
android:id="#+id/image_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="#dimen/margin_logo_to_fields"
android:contentDescription="#string/img_logo_desc"
android:src="#drawable/logo" />
<TextView
android:id="#+id/labelLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/image_login_fields"
android:layout_alignLeft="#id/image_login_fields"
android:layout_marginTop="#dimen/margin_top_label_login"
android:layout_marginLeft="#dimen/margin_left_label_login"
android:text="#string/login"
android:textSize="#dimen/login_txt_size"
/>
<EditText
android:id="#+id/txtFieldLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_left_txt_field_login"
android:layout_alignTop="#id/image_login_fields"
android:layout_toRightOf="#id/labelLogin"
android:layout_alignRight="#id/image_login_fields"
android:layout_marginRight="#dimen/margin_right_txt_field_login"
android:layout_marginTop="#dimen/margin_top_txt_field_login"
android:ems="10"
android:textSize="#dimen/login_txt_size"
android:hint="#string/txtFieldLoginHint"
android:singleLine="true" >
</EditText>
<TextView
android:id="#+id/labelSenha"
android:layout_below="#id/labelLogin"
android:layout_alignLeft="#id/image_login_fields"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_top_label_senha"
android:layout_marginLeft="#dimen/margin_left_label_senha"
android:text="#string/senha"
android:textSize="#dimen/senha_txt_size" />
<EditText
android:id="#+id/txtFieldSenha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtFieldLogin"
android:layout_alignLeft="#id/txtFieldLogin"
android:layout_alignRight="#id/txtFieldLogin"
android:layout_marginTop="#dimen/margin_top_txt_field_senha"
android:ems="10"
android:hint="#string/txtFieldSenhaHint"
android:singleLine="true"
android:textSize="#dimen/senha_txt_size"></EditText>
<ImageButton
android:id="#+id/btnEntrar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#id/image_login_fields"
android:layout_alignBottom="#id/image_login_fields"
android:layout_marginRight="#dimen/margin_right_btn_entrar"
android:layout_marginBottom="#dimen/margin_bottom_btn_entrar"
android:background="#drawable/btn_entrar_clicked"
android:contentDescription="#string/btn_entrar_desc"
/>
<ListView
android:id="#+id/listEmails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/image_login_fields"
android:layout_alignRight="#id/image_login_fields"
android:layout_alignLeft="#id/txtFieldLogin"
android:background="#drawable/rounded_corner"
android:visibility="invisible" >
</ListView>
</RelativeLayout>
<Button
android:id="#+id/btnTeste"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:textSize="#dimen/btn_teste_txt_size"
android:layout_marginRight="#dimen/margin_right_btn_teste"
android:layout_marginBottom="#dimen/margin_bottom_btn_teste"
android:text="#string/btnCredenciaisDeTesteTxt"
android:textColor="#color/white" />
</RelativeLayout>
What you are looking for is the android:windowSoftInputMode attribute in the AndroidManifest. This controls how your screen will respond to the keyboard being shown. Right now it appears that it is using adjustResize and you want adjustPan so in your Activity declaration in the manifest add:
<activity android:windowSoftInputMode="adjustPan"
You can read more about your options here:
http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
If you want the screen to resize you need to rethink your layout.
First, its bad form to have the login background as a separate ImageView. Since you want it to resize you should create a 9 patch for the image at its smallest necessary size. This makes the container define the size of the image, not the image itself.
Second, wrap your TextViews and EditText in a RelativeLayout alone then apply the 9 patch you created as the background of the RelativeLayout. Now you will always have a login box that wraps your Views the way you designed it even when resized.
I wanted to make a button always set at the bottom of the page but will move so it is always shown. The main reason I want this is because when you click into an edit text field the keyboard will pop-up and hide the button. I would like the button to move so it sits above the keyboard when in a field and then will return to the bottom when the keyboard is hidden. Currently I am using a relative layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:background="#FFFFF0">
<RelativeLayout android:orientation="vertical"
android:id="#+id/titlebar1" android:background="#082386"
android:layout_width="fill_parent" android:layout_height="50dip"
android:gravity="center">
<ImageView android:src="#drawable/banner"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:scaleType="fitXY">
</ImageView>
</RelativeLayout>
<Spinner android:layout_height="wrap_content"
android:layout_below="#+id/titlebar1" android:layout_width="wrap_content"
android:id="#+id/NewUsedSpinner" android:prompt="#string/NewUsed_prompt"
android:layout_marginTop="15dip">
</Spinner>
<Spinner android:layout_height="wrap_content"
android:layout_below="#+id/NewUsedSpinner" android:layout_width="wrap_content"
android:id="#+id/MakeSpinner" android:prompt="#string/Make_prompt">
</Spinner>
<Spinner android:layout_height="wrap_content"
android:layout_below="#+id/MakeSpinner" android:layout_width="wrap_content"
android:id="#+id/ModelSpinner" android:prompt="#string/Model_prompt"></Spinner>
<Spinner android:layout_height="wrap_content"
android:layout_below="#+id/NewUsedSpinner" android:layout_width="wrap_content"
android:id="#+id/TrimSpinner" android:prompt="#string/Trim_prompt"></Spinner>
<Spinner android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="#+id/PriceSpinner"
android:layout_below="#+id/TrimSpinner" android:prompt="#string/Price_prompt"
android:layout_marginBottom="5dip"></Spinner>
<TextView android:text="Search within the radius of:"
android:layout_below="#+id/PriceSpinner" android:id="#+id/textView1"
android:layout_width="wrap_content" android:layout_alignLeft="#+id/FilterZip"
android:layout_height="wrap_content" android:textColor="#000"
android:layout_marginTop="5dip"></TextView>
<Spinner android:id="#+id/ZipSpinner" android:layout_width="120dip"
android:layout_below="#+id/textView1" android:layout_height="wrap_content"
android:prompt="#string/Zip_prompt"></Spinner>
<EditText android:layout_width="fill_parent"
android:layout_below="#+id/textView1" android:layout_toRightOf="#+id/ZipSpinner"
android:layout_height="wrap_content" android:text="Zip" android:id="#+id/FilterZip"
android:maxLength="5" android:numeric="integer"></EditText>
<Button android:layout_height="50dip" android:id="#+id/FilterSearchbtn"
android:layout_alignParentBottom="true" android:layout_width="fill_parent"
android:text="Search" android:layout_below="#+id/ZipSpinner"
android:background="#drawable/yellow_btn" android:textStyle="bold"></Button>
</RelativeLayout>
In your Android manifest you would add this to your activity:
<activity android:name=".YourActivity"
android:windowSoftInputMode="adjustResize"
Here's the official documentation: http://developer.android.com/resources/articles/on-screen-inputs.html
Maybe try alignParentBottom="true" on the button so that it will always be on the bottom, you'll have to fiddle with your layout.
(1) If we want to only adjust the screen without view which has (alignParentBottom="true") in relative layout then set below line in activity tag in manifest.xml
android:windowSoftInputMode="adjustPan"
(2) If we want to adjust the whole relative layout with the view which has (alignParentBottom="true") in relative layout then set below line in activity tag in manifest.xml
android:windowSoftInputMode="adjustResize"
(3) If we don't want to adjust the whole relative layout without the view which has (alignParentBottom="true") in relative layout then set below line in activity tag in manifest.xml
android:windowSoftInputMode="adjustPan|adjustResize"
(4) If we remove line android:windowSoftInputMode from the manifest.xml then it will behave like (2) option