I am trying to show scroll bar in my edit text only when height of my edit text reach at the end of my layout height. That's working fine if i am entering/adding blank space but its causing problem when I my text reaches to end of my edit text width. Once my text reaches to end of my edit text width it start showing me scroll bar whereas it should show up when i reach to (height)end of screen.
Please advice how can i resolve this issue. Please find attached image and code for reference.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/editFeedback"
android:layout_width="0dp"
android:layout_height="0dp"
android:bufferType="spannable"
android:gravity="top"
android:hint="Some text"
android:inputType="textCapSentences|textMultiLine"
android:minHeight="120dp"
android:overScrollMode="ifContentScrolls"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:selectAllOnFocus="true"
android:textIsSelectable="true"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="@+id/buttonSend"
app:layout_constraintEnd_toEndOf="@id/guidelineEnd"
app:layout_constraintHeight_default="wrap"
app:layout_constraintStart_toStartOf="@id/guidelineStart"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintVertical_chainStyle="packed"
tools:text="" />
<Button
android:id="@+id/buttonSend"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="Send"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="@+id/barrierEnd"
app:layout_constraintEnd_toEndOf="@id/guidelineEnd"
app:layout_constraintTop_toBottomOf="@+id/editFeedback" />
<TextView
android:id="@+id/Footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginBottom="100dp"
android:text="This is a footer"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guidelineStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="8dp" />
<android.support.constraint.Guideline
android:id="@+id/guidelineEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="8dp" />
<android.support.constraint.Barrier
android:id="@+id/barrierEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="top"
app:constraint_referenced_ids="Footer" />
</android.support.constraint.ConstraintLayout>
A ConstraintLayout is a ViewGroup which allows you to Position and size Views in a flexible way. It is basically RelativeLayout on Steriods. The Views will be positioned and sized w.r.t other Views with the Use of Constraints.
You can make your activity scrollable using ScrollView. Its very simple and effective to use. Just copy code of ScrollView from below and paste it in your layout xml file. You can use this ScrollView with Linear as well as Relative Layout also.
This might help I have edited a few things in the code. I have removed the barrier and changed it with a horizontal guideline and set that guideline to 80% of the screen height and the footer object aligned to that horizontal guideline. Kindly look the code below I hope it solves your problem. If you have any doubt about how I set the constraints I'll be happy to help.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/editFeedback"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="60dp"
android:bufferType="spannable"
android:gravity="top"
android:hint="Some text"
android:inputType="textCapSentences|textMultiLine"
android:minHeight="120dp"
android:overScrollMode="ifContentScrolls"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:selectAllOnFocus="true"
android:textIsSelectable="true"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toEndOf="@id/guidelineEnd"
app:layout_constraintHeight_default="wrap"
app:layout_constraintStart_toStartOf="@id/guidelineStart"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="" />
<Button
android:id="@+id/buttonSend"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="end"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="Send"
android:textAllCaps="false"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toEndOf="@id/guidelineEnd"
app:layout_constraintTop_toBottomOf="@+id/editFeedback"
app:layout_constraintVertical_bias="0.00999999" />
<TextView
android:id="@+id/Footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginBottom="8dp"
android:text="This is a footer"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline" />
<android.support.constraint.Guideline
android:id="@+id/guidelineStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="8dp" />
<android.support.constraint.Guideline
android:id="@+id/guidelineEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="8dp" />
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.8" />
</android.support.constraint.ConstraintLayout>
And also here is the image of how now the layout looks.
Its work my side Please check at your side may be its.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/editFeedback"
android:layout_width="0dp"
android:layout_height="0dp"
android:bufferType="spannable"
android:gravity="top"
android:hint="Some text"
android:inputType="textCapSentences|textMultiLine"
android:minHeight="120dp"
android:overScrollMode="ifContentScrolls"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:selectAllOnFocus="true"
android:textIsSelectable="true"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="@+id/buttonSend"
app:layout_constraintEnd_toEndOf="@+id/guidelineEnd"
app:layout_constraintHeight_default="wrap"
app:layout_constraintStart_toStartOf="@+id/guidelineStart"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintVertical_chainStyle="packed"
tools:text="" />
<Button
android:id="@+id/buttonSend"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="Send"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="@+id/barrierEnd"
app:layout_constraintEnd_toEndOf="@+id/guidelineEnd"
app:layout_constraintTop_toBottomOf="@+id/editFeedback" />
<TextView
android:id="@+id/Footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginBottom="100dp"
android:text="This is a footer"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guidelineStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="8dp" />
<android.support.constraint.Guideline
android:id="@+id/guidelineEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="8dp" />
<android.support.constraint.Barrier
android:id="@+id/barrierEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="top"
app:constraint_referenced_ids="Footer" />
</android.support.constraint.ConstraintLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With