Android force layout update after Visibility.GONE - android

I'm trying to hide the bottom bar when the keyboard is up. I use a size change listener on the list view to detect changes. When the keyboard is up I set the bottom bar to Visibility.GONE. What I get is the center image, which has the bottom bar GONE, but the window not resized correctly. What I want is the right image, which has the text input right above the keyboard. I think it has to do with the window still resizing while I set visibility to GONE?
I'm open to any other solutions besides modifying the visibility, as long as when the keyboard is up the text input is right next to it.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android">
<MyImageView
android:id="#+id/topbar"
style="#style/FillWidth"
android:src="#drawable/topbar"/>
<com.chess.genesis.MyListView
android:id="#+id/msg_list"
android:layout_below="#id/topbar"
android:layout_above="#+id/input_box"/>
<TableRow
android:id="#+id/input_box"
android:layout_above="#+id/botbar">
<EditText
android:id="#+id/new_msg"
style="#style/FillWidth"
android:layout_weight="82"
android:inputType="textCapSentences|textMultiLine"
android:maxLength="140"/>
<com.chess.genesis.MyImageView
android:id="#+id/submit_msg"
style="#style/FillWidth"
android:layout_weight="180"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp"
android:src="#drawable/rsubmit"/>
</TableRow>
<MyImageView
android:id="#+id/botbar"
style="#style/FillWidth"
android:layout_alignParentBottom="true"
android:src="#drawable/botbar"/>
</RelativeLayout>

You can try to use layout_alignWithParentIfMissing for your input box.

Related

I can't change position of textview and buttons in layout editor

My layout preview doesn't show the action bar only the textviews and buttons I added and when I add a new button or textview, it just goes to the top left corner of the screen even though I tried using Relative and Constraint Layouts. I've tried using "Base.Theme.AppCompat.Light.DarkActionBar" but it doesn't solve it. I've had this issue since I installed android studio on my new PC.Here's a screenshot of my layout preview
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Create Account" />
</RelativeLayout>
It's totally normal that your button is on the top left corner if you don't set its position.
If you add this to your Button:
android:layout_centerInParent="true"
Than your Button will be in the center of the root layout.
You can even use ConstraintLayout for this problem. With the help of constraint layout handles you can easily set the button to the centre position.constraint layout centering button
it can be done easily : join right handle first, then left handle, then top and bottom handle.
also with the help of this, layout will not be distorted on different screens

Keyboard does not push layout above EditText

In my application I have the following layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<EditText
android:id="#+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/text"
android:gravity="center_horizontal"
android:hint="#string/input_hint"
android:inputType="textVisiblePassword"
android:padding="#dimen/margin"
android:singleLine="true"
android:textColor="#color/input_text"
android:textColorHint="#color/input_hint">
</EditText>
</LinearLayout>
When EditText is clicked, the keyboard pushes the screen up including the ActionBar so that EditText is just above the keyboard. What I want is for only EditText to come up sitting on the keyboard, but the FragmentContainer that is above remains intact "as background". I got some of this by using android: windowSoftInputMode = "adjustResize" in the AndroidManifest.xml file, but my application is fullscreen and this tag apparently does not work with fullscreen.
As far as I am aware, there's no way to achieve what you're describing.
These are the choices available to you for windowSoftInputMode:
adjustNothing: When the keyboard appears, the window is not adjusted at all. This will stop your fragment_container from being moved or resizing, but will also cause the keyboard to cover your text input field.
adjustResize: When the keyboard appears, the window is "shrunk" vertically. This will cause your fragment_container to occupy less space than when the keyboard is closed, potentially affecting your fragment layout.
adjustPan: When the keyboard appears, the screen is "pushed" upwards. This will cause your fragment_container's top portion to be clipped by the edge of the screen.
adjustUnspecified: Allow the system to choose between the above three options.
Below are some pictures that (hopefully) help illustrate these attributes.
The layout with keyboard closed
From left to right: adjustNothing, adjustResize, and adjustPan

Keyboard overlaps Custom edit text

I have a an EditText with a drawable background (A rectangle shape with corners and a color, nothing fancy)
Case 1 When the EditText gets focus on click, view shifts above but the soft keyboard still partially overlaps it so that the hint is visible properly but the background is trimmed.
Case 2 (Inside a fragment, coz this issue does not occur in an Activity) If I press next from an edit text above the target EditText the background is again trimmed and the keyboard is just touching the bottom of the hint.
I have enclosed it inside a ScrollView, tried android:windowSoftInputMode="stateAlwaysHidden|adjustResize" (with different combinations too) but nothing seems to work.
Is there a way to override the y-axis by which the view is pushed when soft keyboard opens?
Half of the job is done by Scrollview itself,
Try to writing these line in you onFocusChanged method of edittext
editText.requestLayout();
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
and your .xml would be like -
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:weightSum="1">
.... your editetexts here...
</ScrollView>
</LinearLayout>

Status bar always on screen

Good day (or evening, or night)
I'm developing an app for android and I'm very curious about one thing. I have an activity, where user chats with another, like "im" chat. There are an EditText on the bottom and some kind of actionbar on the top. What I need is when user enters a message and the software keyboard is on screen, my activity should move up, but the actionbar should still be "glued" to the top of the screen, because it has some valuable controls on it.
Again, that's not an ActionBar, but just a 48dp height layout in a parent vertical linear layout. So I need to know is there an easy way to prevent it from moving to the top, when the layout moves off the screen.
I tried to put everything in a FrameLayout and put this bar on top of it, but on keyboard opens it goes off the screen too...
On you Activity at AndroidManifest you should put this: android:windowSoftInputMode="adjustResize"
Use something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.myapp.MyActionBar
android:layout_width="match_parent"
android:layout_height="48dp"/>
<LinearLayout
android:id="#+id/mylayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1dp"/>
<!-- Add your edittext and button -->
</LinearLayout>
This will make sure the actionbar and edittext + button are allways on screen, and the mylayout takes up the rest of the screen. When your keyboard is shown, the mylayout will shrink.
Try adding android:windowSoftInputMode="adjustResize" to your activity in the manifest. This tells Android to completely resize your layout when the keyboard comes up, rather than pan it. Note that if there isn't enough room for the entire layout this still won't work. But you ought to be able to make it work if your top level layout is a RelativeLayout, with the edit text set to align bottom, the top bar to align top, and the middle section to fill_parent and be above the edit text and below the bar.
use a RelativeLayout as your base Layout and add android:layout_alignParentTop="true" to your action bar to keep it up
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/action_bar_layout"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentTop="true" >
</LinearLayout>
<TextView
android:id="#+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>

Android Show/Hide Widget Resize Fill Parent

I have an EditText with a Button next to it. The button is hidden at first so the EditText takes up the full screen, which is good. When they tap the EditText I have the button appear next to the EditText, and it resizes itself accordingly. However, when I hide the Button (I set visibility to gone), the EditText does NOT resize to full screen (leaving a gap to the right of the EditText). Any tips?
I have tried putting the EditText and Button in both a LinearLayout and a TableLayout (with stretchable column, etc) and I see the same behavior. I also tried doing some runtime calls to removeView/addView stuff and that didnt work. I also tried calling invalidate() on both the EditText and its parent.
Thanks!
I encountered the same question, I want to change the size of an EditText when hiding and showing a Button which stands next to it, but the EditText's size will not shrink after call setVisibility(View.VISIBLE) on the button. I solved it by adding a android:layout_weight="1" to the EditText.
The layout xml looks like this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/search_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<Button
android:id="#+id/hide_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn"
/>
</LinearLayout>

Categories

Resources