ImageView resizes when keyboard open

前端 未结 3 560
悲&欢浪女
悲&欢浪女 2021-01-26 13:22

This is my code




        
相关标签:
3条回答
  • 2021-01-26 13:53

    remove the parent layout (the RelativeLayout) and make the LinearLayout containing the dialog box only, the parent! plus, add android:windowSoftInputMode="stateVisible|adjustResize" to the AndroidManifest.xml

    0 讨论(0)
  • 2021-01-26 14:01

    I had a similar issue in which a custom View - ParallaxBackground - that I've adapted was supposed to act as a background image with a parallax effect driven by the scroll of a ViewPager in the same activity.

    In other words, I have a View that displays an image with a width slightly larger than the screen's and when the user scrolls along the ViewPager, the image in the ParallaxBackground scrolls a little as well.

    Now in my case, I had some EditTexts inside my ViewPager's Fragments and when the user clicked on them, causing the soft keyboard to show up, the ParallaxBackground (and consequently, the background image) would be re-sized and squeezed "against my will".

    So I added a boolean isBackground, two ints for fixedWidth and fixedHeight and overrode my View's onMeasure() like so:

     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    
    
        if(isBackground) 
        // If this is being used as a background and is supposed to occupy the whole screen...
        {
                        // force the View to have the specified dimensions
            setMeasuredDimension(fixedWidth, fixedHeight);
        }
        // ...aply default measures...
        else
        {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    
     }
    

    I know this is not a "beautiful" solution but, even though my answer is not 100% related to your problem, you might want to try extending the ImageView class and overriding onMeasure.

    Then, in your onCreate method you can set isBackground to true and give fixedWidth and fixedHeight the values for your measured screen width and height.

    0 讨论(0)
  • 2021-01-26 14:05

    Add background image from Java not from XML:

    getActivity().getWindow().setBackgroundDrawable(getResources().getDrawable(R.drawable.splash_image));
    

    In manifest add

    android:windowSoftInputMode="adjustResize|stateHidden"
    

    The state hidden can written as per requirement if you have to hide the keyboard on opening of screen

    0 讨论(0)
提交回复
热议问题