Skip to content

Commit

Permalink
Merge pull request #7 from CraveFood/fix-scroll-bug
Browse files Browse the repository at this point in the history
Fixing scroll bug on operation text
  • Loading branch information
KennedySDias authored Feb 25, 2019
2 parents 94ab64c + 2bad0c7 commit 000ee6d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.HorizontalScrollView
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
Expand Down Expand Up @@ -33,6 +34,7 @@ class CalculatorFragment : Fragment() {

viewModel.currentExpressionObservable.observe(this, Observer {
textViewOperation.text = it
focusOperationText()
})

viewModel.resultObservable.observe(this, Observer {
Expand Down Expand Up @@ -94,6 +96,13 @@ class CalculatorFragment : Fragment() {
else activity?.onBackPressed()
}

private fun focusOperationText() {
horizontalScrollView.postDelayed(
Runnable { horizontalScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT) },
100L
)
}

companion object {
fun newInstance(
cancelListener: (() -> Unit)? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
android:paddingStart="8dp">

<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp"
Expand Down
2 changes: 2 additions & 0 deletions cravecalculator/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<resources>
<public />

<string name="app_name">cravecalculator</string>

<string name="_point">.</string>
Expand Down
2 changes: 1 addition & 1 deletion cravecalculator/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</style>

<style name="TextViewOperation">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">24sp</item>
<item name="android:layout_gravity">end</item>
Expand Down

0 comments on commit 000ee6d

Please sign in to comment.