Rectangle 27 25

Your 2nd code snippet is almost correct, but you need to specify pixel sizes - not FILL_PARENT/MATCH_PARENT. This should work:

v.measure(MeasureSpec.makeMeasureSpec(parentView.getWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(MAX_HEIGHT, MeasureSpec.AT_MOST));
final int targetHeight = v.getMeasuredHeight();

You'll need to have a reference to the ViewGroup that v is a child of to get its width, and define MAX_HEIGHT (or perhaps use the parent View's height?).

Also, you should change the height parameters of the two TextViews that are within the horizontal LinearLayout to wrap_content, as using match_parent here may cause problems. The LinearLayout is set to wrap_content, but the two children don't specify a height.

That helped me too, but in my case it was not the full story. This is how I finally solved it: stackoverflow.com/a/36184454/854396

android - Accurate way to determine the measured height of a view, eve...

android
Rectangle 27 200

Based on yghm's workaround, I coded up a convenience class that allows me to solve the problem with a one-liner (after adding the new class to my source code of course). The one-liner is:

AndroidBug5497Workaround.assistActivity(this);

And the implementation class is:

public class AndroidBug5497Workaround {

    // For more information, see https://issuetracker.google.com/issues/36911528
    // To use this class, simply invoke assistActivity() on an Activity that already has its content view set.

    public static void assistActivity (Activity activity) {
        new AndroidBug5497Workaround(activity);
    }

    private View mChildOfContent;
    private int usableHeightPrevious;
    private FrameLayout.LayoutParams frameLayoutParams;

    private AndroidBug5497Workaround(Activity activity) {
        FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
        mChildOfContent = content.getChildAt(0);
        mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            public void onGlobalLayout() {
                possiblyResizeChildOfContent();
            }
        });
        frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
    }

    private void possiblyResizeChildOfContent() {
        int usableHeightNow = computeUsableHeight();
        if (usableHeightNow != usableHeightPrevious) {
            int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
            int heightDifference = usableHeightSansKeyboard - usableHeightNow;
            if (heightDifference > (usableHeightSansKeyboard/4)) {
                // keyboard probably just became visible
                frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
            } else {
                // keyboard probably just became hidden
                frameLayoutParams.height = usableHeightSansKeyboard;
            }
            mChildOfContent.requestLayout();
            usableHeightPrevious = usableHeightNow;
        }
    }

    private int computeUsableHeight() {
        Rect r = new Rect();
        mChildOfContent.getWindowVisibleDisplayFrame(r);
        return (r.bottom - r.top);
    }
}

Thanks! I have no idea why, but I had to replace return (r.bottom - r.top); with return r.bottom to get it work on my HTC One Mini, otherwise the activity view would be pushed too high by the size of the status bar. I haven't tested it on another device yet though. Hope that can help.

Hi Joseph johnson, I used your code and it worked perfectly. But now days facing an issue on some small devices that it shows the gap (blank screen) between keyboard and layout. Have you any idea about this issue? I also tried return r.bottom.

Joseph Johnson : I have implemented your method, its working fine when we click on the top edit text but when we click on bottom edittext all design goes up

Unfortunately it doesn't work on Nexus 7 (2013). It still pans even with adjustNothing set.

Awesome answer, thank you very much. It's working on a Nexus 6 but instead of using frameLayoutParams.height = usableHeightSansKeyboard; i have to use frameLayoutParams.height = usableHeightNow; If I don't this some elements falls outside the screen.

Android How to adjust layout in Full Screen Mode when softkeyboard is ...

android android-layout android-widget android-softkeyboard
Rectangle 27 189

Based on yghm's workaround, I coded up a convenience class that allows me to solve the problem with a one-liner (after adding the new class to my source code of course). The one-liner is:

AndroidBug5497Workaround.assistActivity(this);

And the implementation class is:

public class AndroidBug5497Workaround {

    // For more information, see https://issuetracker.google.com/issues/36911528
    // To use this class, simply invoke assistActivity() on an Activity that already has its content view set.

    public static void assistActivity (Activity activity) {
        new AndroidBug5497Workaround(activity);
    }

    private View mChildOfContent;
    private int usableHeightPrevious;
    private FrameLayout.LayoutParams frameLayoutParams;

    private AndroidBug5497Workaround(Activity activity) {
        FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
        mChildOfContent = content.getChildAt(0);
        mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            public void onGlobalLayout() {
                possiblyResizeChildOfContent();
            }
        });
        frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
    }

    private void possiblyResizeChildOfContent() {
        int usableHeightNow = computeUsableHeight();
        if (usableHeightNow != usableHeightPrevious) {
            int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
            int heightDifference = usableHeightSansKeyboard - usableHeightNow;
            if (heightDifference > (usableHeightSansKeyboard/4)) {
                // keyboard probably just became visible
                frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
            } else {
                // keyboard probably just became hidden
                frameLayoutParams.height = usableHeightSansKeyboard;
            }
            mChildOfContent.requestLayout();
            usableHeightPrevious = usableHeightNow;
        }
    }

    private int computeUsableHeight() {
        Rect r = new Rect();
        mChildOfContent.getWindowVisibleDisplayFrame(r);
        return (r.bottom - r.top);
    }
}

This solution works for me as well! Cheers to you bro!

Thanks! I have no idea why, but I had to replace return (r.bottom - r.top); with return r.bottom to get it work on my HTC One Mini, otherwise the activity view would be pushed too high by the size of the status bar. I haven't tested it on another device yet though. Hope that can help.

Hi Joseph johnson, I used your code and it worked perfectly. But now days facing an issue on some small devices that it shows the gap (blank screen) between keyboard and layout. Have you any idea about this issue? I also tried return r.bottom.

Joseph Johnson : I have implemented your method, its working fine when we click on the top edit text but when we click on bottom edittext all design goes up

Unfortunately it doesn't work on Nexus 7 (2013). It still pans even with adjustNothing set.

Android How to adjust layout in Full Screen Mode when softkeyboard is ...

android android-layout android-widget android-softkeyboard
Rectangle 27 128

int minLat = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int minLon = Integer.MAX_VALUE;
int maxLon = Integer.MIN_VALUE;

for (GeoPoint item : items) 
{ 

      int lat = item.getLatitudeE6();
      int lon = item.getLongitudeE6();

      maxLat = Math.max(lat, maxLat);
      minLat = Math.min(lat, minLat);
      maxLon = Math.max(lon, maxLon);
      minLon = Math.min(lon, minLon);
 }

mapController.zoomToSpan(Math.abs(maxLat - minLat), Math.abs(maxLon - minLon));
mapController.animateTo(new GeoPoint( (maxLat + minLat)/2, 
(maxLon + minLon)/2 ));

edit: Ryan gave a nice suggestion : to put a padding so that some of the point don't lie on the edges (thanks Ryan!)

double fitFactor = 1.5;
mapController.zoomToSpan((int) (Math.abs(maxLat - minLat) * fitFactor), (int)(Math.abs(maxLon - minLon) * fitFactor));

excellent! make a square and zoom to center

double fitFactor = 1.5
mapController.zoomToSpan((int)(Math.abs(maxLat - minLat) * fitFactor), (int)(Math.abs(maxLon - minLon) * fitFactor));

It can also contain a check ie items list should not be empty otherwise the map is zoomed to level 1. For me, it is working for most of the cases.

gps - Android MapView -setting zoom automatically until all ItemizedOv...

android gps android-mapview
Rectangle 27 128

int minLat = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int minLon = Integer.MAX_VALUE;
int maxLon = Integer.MIN_VALUE;

for (GeoPoint item : items) 
{ 

      int lat = item.getLatitudeE6();
      int lon = item.getLongitudeE6();

      maxLat = Math.max(lat, maxLat);
      minLat = Math.min(lat, minLat);
      maxLon = Math.max(lon, maxLon);
      minLon = Math.min(lon, minLon);
 }

mapController.zoomToSpan(Math.abs(maxLat - minLat), Math.abs(maxLon - minLon));
mapController.animateTo(new GeoPoint( (maxLat + minLat)/2, 
(maxLon + minLon)/2 ));

edit: Ryan gave a nice suggestion : to put a padding so that some of the point don't lie on the edges (thanks Ryan!)

double fitFactor = 1.5;
mapController.zoomToSpan((int) (Math.abs(maxLat - minLat) * fitFactor), (int)(Math.abs(maxLon - minLon) * fitFactor));

excellent! make a square and zoom to center

double fitFactor = 1.5
mapController.zoomToSpan((int)(Math.abs(maxLat - minLat) * fitFactor), (int)(Math.abs(maxLon - minLon) * fitFactor));

It can also contain a check ie items list should not be empty otherwise the map is zoomed to level 1. For me, it is working for most of the cases.

gps - Android MapView -setting zoom automatically until all ItemizedOv...

android gps android-mapview
Rectangle 27 66

Thanks, I was wondering about this and found this thread really helpful.

The last comment - "fullscreen mode doesn't resize" - brought to an immediate close several days of searching and puzzling. Thank you so much nmr for that essential nugget of information.

The window may not resize, but the window insets can change and we can get them (under certain configuration), and since OP is asking for "how to adjust layout", this is in fact possible. Please refer to my answer below for a solution.

Android How to adjust layout in Full Screen Mode when softkeyboard is ...

android android-layout android-widget android-softkeyboard
Rectangle 27 65

Thanks, I was wondering about this and found this thread really helpful.

The last comment - "fullscreen mode doesn't resize" - brought to an immediate close several days of searching and puzzling. Thank you so much nmr for that essential nugget of information.

Android How to adjust layout in Full Screen Mode when softkeyboard is ...

android android-layout android-widget android-softkeyboard
Rectangle 27 35

This warning is caused by a bug introduced in Google Play Services 9.x. It can be safely ignored, it will not cause any issues with your app and should go away with a future update to play services.

compile 'com.google.android.gms:play-services-gcm:8.+'

@BrentM but due to that my map is not loading.Which is infecting our user base on production.

@adarsh From my experience this log message is not related to map loading failure. However it is impossible for me to comment on your situation. Check the SHA1 hashes listed in the developer API console as this is the most common cause of map loading failure.

strange but with the same SHA1 hash I am able to load map on other devices, and I am also getting same log as mentioned in this question. @BrentM

android - Google maps in my app is not visible - Stack Overflow

android android-keystore
Rectangle 27 32

You can toggle fullScreen mode when soft keyboard is shown. This allows the "adjustPan" to work correctly.

In other words, I still use @android:style/Theme.Black.NoTitleBar.Fullscreen as part of the application theme and stateVisible|adjustResize as part of the activity window soft input mode but to get them to work together I must toggle fullscreen mode before the keyboard comes up.

Use the following Code:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

I appreciate that you have given time to the problem, +1 for that. I will definitely test this approach and let you know soon if it worked for me, thanks.

Is working as suspected! Really good solution! +1 from my side.

the keyboard snaps,making the keyboard background black. The snapping effect doesn't look good :(

Android How to adjust layout in Full Screen Mode when softkeyboard is ...

android android-layout android-widget android-softkeyboard
Rectangle 27 31

You can toggle fullScreen mode when soft keyboard is shown. This allows the "adjustPan" to work correctly.

In other words, I still use @android:style/Theme.Black.NoTitleBar.Fullscreen as part of the application theme and stateVisible|adjustResize as part of the activity window soft input mode but to get them to work together I must toggle fullscreen mode before the keyboard comes up.

Use the following Code:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

I appreciate that you have given time to the problem, +1 for that. I will definitely test this approach and let you know soon if it worked for me, thanks.

Is working as suspected! Really good solution! +1 from my side.

Android How to adjust layout in Full Screen Mode when softkeyboard is ...

android android-layout android-widget android-softkeyboard
Rectangle 27 16

<ListView />
 <RelativeLayout
    android:id="@android:id/empty"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
       // Add whatever you want here including your header
 </RelativeLayout>

That way the header/footer does not scroll as part of the list. I already got that like I said in the question and would prefer the header and footer to be part of the scrolling list. Wrapping a scroll view around both does not work either..

No, you add the header with addHeaderView(R.layout.your_header); And you also add the header into the id/empty. That way it scroll's when you have items, and is still shown when you don't. Make use of the <include/> and <merge/> tags to stop XML code duplication

oh.. I get the trick now. This is a neat idea.

android - List activity with header, footer and empty all visible - St...

android listview
Rectangle 27 14

public boolean isEmpty() {
    return false;
}

you learn something new every day, and today you taught me something new

android - List activity with header, footer and empty all visible - St...

android listview
Rectangle 27 508

display:none
visibility:hidden

Android : difference between invisible and gone? - Stack Overflow

android android-xml xml-attribute
Rectangle 27 8

I had to face this problem too and had a work around which i checked on HTC one, galaxy s1, s2, s3, note and HTC sensation.

put a global layout listener on the root view of your layout

mRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){
            public void onGlobalLayout() {
                checkHeightDifference();
            }
    });

and in there i checked the height difference and if the height difference of the screen is bigger then a third on the screen height then we can assume the keyboard is open. took it from this answer.

private void checkHeightDifference(){
    // get screen frame rectangle 
    Rect r = new Rect();
    mRootView.getWindowVisibleDisplayFrame(r);
    // get screen height
    int screenHeight = mRootView.getRootView().getHeight();
    // calculate the height difference
    int heightDifference = screenHeight - (r.bottom - r.top);

    // if height difference is different then the last height difference and
    // is bigger then a third of the screen we can assume the keyboard is open
    if (heightDifference > screenHeight/3 && heightDifference != mLastHeightDifferece) {
        // keyboard visiblevisible
        // get root view layout params
        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mRootView.getLayoutParams();
        // set the root view height to screen height minus the height difference
        lp.height = screenHeight - heightDifference;
        // call request layout so the changes will take affect
        .requestLayout();
        // save the height difference so we will run this code only when a change occurs.
        mLastHeightDifferece = heightDifference;
    } else if (heightDifference != mLastHeightDifferece) {
        // keyboard hidden
        PFLog.d("[ChatroomActivity] checkHeightDifference keyboard hidden");
        // get root view layout params and reset all the changes we have made when the keyboard opened.
        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mRootView.getLayoutParams();
        lp.height = screenHeight;
        // call request layout so the changes will take affect
        mRootView.requestLayout();
        // save the height difference so we will run this code only when a change occurs.
        mLastHeightDifferece = heightDifference;
    }
}

this is probably not bullet proof and maybe on some devices it will not work but it worked for me and hope it will help you too.

Needed some adjustements, but it worked. In the Nexus 7 2013 I had to decrease the keyboard height (screenHeight/3) by some pixels. Nice idea, thanks!

Android How to adjust layout in Full Screen Mode when softkeyboard is ...

android android-layout android-widget android-softkeyboard
Rectangle 27 175

From Documentation you can say that

View.INVISIBLE
View.GONE

Does the idea need to be cleared? It seems clear enough for me just from the explanation.

@JanDvorak :) Great! I have no answer for your question. If you think this was very clear for all users, then the accepted answer should be a comment and have a link of documentation site. Am I correct?

Thanks for clearing it up with those images. I understood what it was from the documentation (actually, from just the naming of the variables) but wasn't 100% sure. Still had the doubt in my mind. This cleared things up completely. Thanks a ton

Android : difference between invisible and gone? - Stack Overflow

android android-xml xml-attribute
Rectangle 27 7

android:windowSoftInputMode="adjustResize"
WindowManager.LayoutParams.FLAG_FULLSCREEN

Either disable fullscreen mode for your activity. Activity is not re-sized in fullscreen mode. You can do this either in xml (by changing the theme of the activity) or in Java code. Add the following lines in your onCreate() method.

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);   
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);`
  • Use an alternative way to achieve fullscreen mode. Add the following code in your onCreate() method. getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); View decorView = getWindow().getDecorView(); // Hide the status bar. int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions);`

Please note that method-2 only works in Android 4.1 and above.

@AnshulTyagi method-2 only works in Android 4.1 and above.

Tested on 5.0 and 4.4.2, Nexus 9 and Samsung s4 respectively, 2nd method does not work.

2nd method simply does not work and I wasted a lot of time on it.

Android How to adjust layout in Full Screen Mode when softkeyboard is ...

android android-layout android-widget android-softkeyboard
Rectangle 27 7

I had to face this problem too and had a work around which i checked on HTC one, galaxy s1, s2, s3, note and HTC sensation.

put a global layout listener on the root view of your layout

mRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){
            public void onGlobalLayout() {
                checkHeightDifference();
            }
    });

and in there i checked the height difference and if the height difference of the screen is bigger then a third on the screen height then we can assume the keyboard is open. took it from this answer.

private void checkHeightDifference(){
    // get screen frame rectangle 
    Rect r = new Rect();
    mRootView.getWindowVisibleDisplayFrame(r);
    // get screen height
    int screenHeight = mRootView.getRootView().getHeight();
    // calculate the height difference
    int heightDifference = screenHeight - (r.bottom - r.top);

    // if height difference is different then the last height difference and
    // is bigger then a third of the screen we can assume the keyboard is open
    if (heightDifference > screenHeight/3 && heightDifference != mLastHeightDifferece) {
        // keyboard visiblevisible
        // get root view layout params
        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mRootView.getLayoutParams();
        // set the root view height to screen height minus the height difference
        lp.height = screenHeight - heightDifference;
        // call request layout so the changes will take affect
        .requestLayout();
        // save the height difference so we will run this code only when a change occurs.
        mLastHeightDifferece = heightDifference;
    } else if (heightDifference != mLastHeightDifferece) {
        // keyboard hidden
        PFLog.d("[ChatroomActivity] checkHeightDifference keyboard hidden");
        // get root view layout params and reset all the changes we have made when the keyboard opened.
        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mRootView.getLayoutParams();
        lp.height = screenHeight;
        // call request layout so the changes will take affect
        mRootView.requestLayout();
        // save the height difference so we will run this code only when a change occurs.
        mLastHeightDifferece = heightDifference;
    }
}

this is probably not bullet proof and maybe on some devices it will not work but it worked for me and hope it will help you too.

Needed some adjustements, but it worked. In the Nexus 7 2013 I had to decrease the keyboard height (screenHeight/3) by some pixels. Nice idea, thanks!

Android How to adjust layout in Full Screen Mode when softkeyboard is ...

android android-layout android-widget android-softkeyboard
Rectangle 27 7

I have used this combination but no luck....

but its working for me, ok only put adjustResize

I have used it too....please make you are doing it in full screen mode and on which device are you testing?

the above code is working fine without full screen but adding full screen either from xml or from code ... It is not working...Please read the question carefully.

Android How to adjust layout in Full Screen Mode when softkeyboard is ...

android android-layout android-widget android-softkeyboard
Rectangle 27 6

I tried the solution from Joseph Johnson, but like others I ran into the gap-between-content-and-keyboard problem. The problem occurs because the soft input mode is always pan when using full-screen mode. This panning interferes with Joseph's solution when you activate an input field that would be hidden by the soft input.

When the soft input appears, the content is first panned based on its original height, and then resized by the layout requested by the Joseph's solution. The resizing and subsequent layout do not undo the panning, which results in the gap. The full order of events is:

  • Layout of content (= actual resizing of content)

It is not possible to disable panning, but it is possible to force the pan offset to be 0 by changing the height of the content. This can be done in the listener, because it is run before panning takes place. Setting the content height to the available height results in a smooth user experience, i.e. no flickering.

I also made these changes. If any of these introduce issues, let me know:

  • Switched determination of available height to use getWindowVisibleDisplayFrame. The Rect is cached to prevent a little bit of unneeded garbage.
  • Allow the listener to be removed too. This is useful when you reuse an activity for different fragments having different full-screen requirements.
  • Do not distinguish between keyboard shown or hidden, but always set the content height to the visible display frame height.

It has been tested on a Nexus 5, and emulators running API levels 16-24 with screen sizes ranging from tiny to big.

The code has been ported to Kotlin, but porting my changes back to Java is simple. Let me know if you need help:

class AndroidBug5497Workaround constructor(activity: Activity) {
    private val contentContainer = activity.findViewById(android.R.id.content) as ViewGroup
    private val rootView = contentContainer.getChildAt(0)
    private val rootViewLayout = rootView.layoutParams as FrameLayout.LayoutParams
    private val viewTreeObserver = rootView.viewTreeObserver
    private val listener = { possiblyResizeChildOfContent() }

    private val contentAreaOfWindowBounds = Rect()
    private var usableHeightPrevious = 0

    // I call this in "onResume()" of my fragment
    fun addListener() {
        viewTreeObserver.addOnGlobalLayoutListener(listener)
    }

    // I call this in "onPause()" of my fragment
    fun removeListener() {
        viewTreeObserver.removeOnGlobalLayoutListener(listener)
    }

    private fun possiblyResizeChildOfContent() {
        contentContainer.getWindowVisibleDisplayFrame(contentAreaOfWindowBounds)
        val usableHeightNow = contentAreaOfWindowBounds.height()
        if (usableHeightNow != usableHeightPrevious) {
            rootViewLayout.height = usableHeightNow
            // Change the bounds of the root view to prevent gap between keyboard and content, and top of content positioned above top screen edge.
            rootView.layout(contentAreaOfWindowBounds.left, contentAreaOfWindowBounds.top, contentAreaOfWindowBounds.right, contentAreaOfWindowBounds.bottom)
            rootView.requestLayout()

            usableHeightPrevious = usableHeightNow
        }
    }
}

This seems to be the best answer. I ported to java here gist.github.com/grennis/2e3cd5f7a9238c59861015ce0a7c5584 . Note I was getting exceptions that observer was not alive, and had to check for that as well.

Android How to adjust layout in Full Screen Mode when softkeyboard is ...

android android-layout android-widget android-softkeyboard
Rectangle 27 6

I have used this combination but no luck....

but its working for me, ok only put adjustResize

I have used it too....please make you are doing it in full screen mode and on which device are you testing?

the above code is working fine without full screen but adding full screen either from xml or from code ... It is not working...Please read the question carefully.

Android How to adjust layout in Full Screen Mode when softkeyboard is ...

android android-layout android-widget android-softkeyboard