1

I have the next layout

enter image description here

And when keyboard comes up, i wan't that green marked part of layout stays always visible. Another words i need to see both EditText and Button.

Here is my code sketch:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="16dp"
tools:context="com.mynfo.concept.auth.AuthActivity">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/titleImageView"
    android:layout_gravity="center"
    android:src="@drawable/title_auth"
    android:layout_weight="0"
    android:layout_marginTop="48dp"
    android:layout_marginBottom="48dp"
    />

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0"
    android:layout_marginBottom="8dp"
    android:focusable="true"
    android:focusableInTouchMode="true"
    >

    <EditText
        android:id="@+id/barcode_editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:inputType="number"
        android:textColorHint="@color/darker_grey"
        android:hint="edittext"
        android:maxLength="15"
        android:ellipsize="end"
        android:ems="10"
        android:background="#0000"
        android:layout_gravity="left|center_vertical"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_camera"
        android:layout_gravity="right|center_vertical"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/grey"
        android:layout_gravity="bottom"/>

</FrameLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_weight="1">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <com.melnykov.fab.FloatingActionButton
            android:id="@+id/button_scan"
            android:layout_width="64dp"
            android:layout_height="64dp"
            fab:fab_colorNormal=    "@color/turquoise"
            fab:fab_colorPressed=   "@color/turquoise_black"
            fab:fab_colorRipple=    "@color/turquoise_light"
            android:src="@android:drawable/ic_menu_camera"
            android:layout_gravity="center"/>
    </FrameLayout>

    <Button
        android:id="@+id/button_link_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Authorize"
        android:background="@drawable/button_authorize_selector"
        android:enabled="false"
        android:layout_weight="0"
        />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.2">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_gravity="center"
            android:gravity="center">

            <TextView
                style="@style/TextViewPrimary"
                android:layout_marginLeft="32dp"
                android:layout_marginRight="32dp"
                android:textSize="16sp"
                android:text="Enter your name"
                android:gravity="center" />

            <com.mynfo.concept.views.FontFitTextView
                style="@style/TextViewSecondary"
                android:text="And then you will got the access"
                android:gravity="center" />

        </LinearLayout>


        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/authenticatingView"
            android:background="#fff">

            <ProgressBar
                style="?android:attr/progressBarStyleLarge"
                android:indeterminateOnly="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/authenticatingProgressBar"
                android:layout_gravity="center"/>

        </FrameLayout>

    </FrameLayout>




</LinearLayout>

What haven't worked: adjustPan, adjustSize with or without layout weights.

Maybe I'm doing something wrong?

Thanks for the further help.

P.S. I know that this code feels redundant, but there were some purposes like screen adapting.

Yurii Kot
  • 316
  • 3
  • 11

1 Answers1

1

In your AndroidMenifest.xml file inside your tag use

windowsSoftInputMode = "adjustResize"

Or take whole layout inside ScrollView

windowsSoftInputMode = "adjustPan"

Example code snippet:

        <activity
            android:name=".activityname"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustPan|adjustResize" >

        </activity>

Use android:fillViewport="true" tag in ScrollView. And to avoid layout size bugs, use margin in Top ScrollView and don't use it in ScrollView child.

And add this in OnCreate

    scrollView = (ScrollView) this.findViewById(R.id.scrollView);
    scrollView.setVerticalScrollBarEnabled(false);
    imageView = (ImageView) findViewById(R.id.imageView);

    this.findViewById(android.R.id.content).addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            scrollView.scrollTo(0, imageView.getHeight() + ((ViewGroup.MarginLayoutParams) imageView.getLayoutParams()).topMargin);
        }
    });

See the comments..

Yurii Kot
  • 316
  • 3
  • 11
TapanHP
  • 5,969
  • 6
  • 37
  • 66
  • Hi, thank you for the feedback, but the methods above have no right affect – Yurii Kot Jul 07 '16 at 14:06
  • Ok I will let you tell after making my own example for you surely just wait I will make it for you .. have you put it in right place in Android manifest file ? – TapanHP Jul 07 '16 at 14:22
  • Just try to put all your XML content in scroll view and then try above methods and let me know if working @kot – TapanHP Jul 07 '16 at 14:24
  • I put all xml into scrollView and programmaticaly scroll the view to edittext in onLayoutChange, but the weights are not working now. The main purpose for calculating margin using weight is to make views evenly located at screen. fitViewPort have bad lags. i need to locate margins for all of the views. Is there any another way to do it? – Yurii Kot Jul 07 '16 at 16:27
  • yes ok weight will never work with scroll ..@YuriyKot ok let just me try it out – TapanHP Jul 07 '16 at 16:54
  • try to make layout in scrollview to adjustable with weight see this answer :http://stackoverflow.com/a/10312631/5476209 – TapanHP Jul 07 '16 at 17:22
  • I provided full code. I tried this solution - scrollview in this size a bit larger than screen @Tapan – Yurii Kot Jul 08 '16 at 09:50
  • and your button is adjusted as you needed ? – TapanHP Jul 08 '16 at 09:51
  • Actually here is full solution, please update yours, and i mark you green. Thanks! I don't need any adjust. I need: android:fillViewport="true" in scroll view scrollView.setVerticalScrollBarEnabled(false); and then i put scrollView.scrollTo(0, imageView.getHeight() + ((ViewGroup.MarginLayoutParams) imageView.getLayoutParams()).topMargin); this.findViewById(android.R.id.content).addOnLayoutChangeListener(new View.OnLayoutChangeListener() {onLayoutChange(){.HERE.} } Next comment: – Yurii Kot Jul 08 '16 at 10:36
  • I also put all "old root view" margin to scroll view.(scroll view larges than screen in another case when using android:fillViewport="true" ) And finally weights are working with ... margin! The problem was: when keyboard opens my views are losing weights and become too close one to another. But margin in normal state does nothing to views! – Yurii Kot Jul 08 '16 at 10:36
  • from where you got this solution ? can you give a link ? would be great help @YuriyKot because i m not able to getting from your comments so please – TapanHP Jul 08 '16 at 11:09