sneha
sneha

Reputation: 41

Use scrollview and adjustPan together android

In my manifest I have written

 <activity android:name=".email" 
           android:label="@string/app_name"
           android:theme="@android:style/Theme.NoTitleBar"
           android:windowSoftInputMode="adjustPan">         
 </activity>

And in my layout I have written

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white" >

<ImageView
    android:id="@+id/bottomImage"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:background="@drawable/ic_backdrop_wave" />

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dip"
    android:isScrollContainer="false" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <EditText>
        </EditText>

        <EditText>
        </EditText>

        <EditText>
        </EditText>
    </LinearLayout>
</ScrollView>

So, When I clicked on any edit text it will not re sizes the imageview but It will also disable scroll view.

Now what I have to do to come out, I want such layout in which height of image view will not change and it will stick to align parent bottom while any soft keyboard is open, and scroll view is enable while soft key board is open.

Upvotes: 4

Views: 5606

Answers (2)

Ibrahim Broachwala
Ibrahim Broachwala

Reputation: 101

Here is the solution.

Make sure your Image is inside the single child inside ScrollView aligned to bottom, like this.

<ScrollView
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_width="match_parent"
        android:fillViewport="true"
        android:isScrollContainer="true"
        android:layout_height="0dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
          ....

          ....

           <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/bottom_illustration"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/some_text_view"
                app:layout_constraintVertical_bias="1.0"
                app:srcCompat="@drawable/login_illustration" />

       </androidx.constraintlayout.widget.ConstraintLayout>

 </ScrollView>

Add the following properties to ScrollView

android:fillViewport="true"
android:isScrollContainer="true"

Add this to under your activity tag in AndroidManifest.xml

android:windowSoftInputMode="adjustResize"

Upvotes: 0

droid kid
droid kid

Reputation: 7609

Did you tried using

android:windowSoftInputMode="adjustResize"

This will not resize the imageview, instead it will auto adjust the screen when the keyboard popup

Upvotes: 2

Related Questions