Issue
I have a text view inside a RelativeLayout. It's working fine in LTR layout. But when I change it to RTL the view inside a RelativeLayout moves out of visible screen. I was checking it in Layout inspector and I could see it being out of the screen visible area. The view is visible but it's not in the screen.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:id="@+id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_empty"
android:layout_gravity="center" />
<TextView
android:id="@+id/empty_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingTop="12dp"
android:paddingRight="16dp"
android:textAlignment="center"
android:textColor="@color/data_color"
android:textSize="@dimen/text_medium"
android:gravity="center_horizontal" />
<RelativeLayout
android:id="@+id/refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:minHeight="40dp">
<TextView
android:id="@+id/refresh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="@string/refresh" />
<ProgressBar
android:id="@+id/progress"
android:layout_width="@dimen/progressbar_width"
android:layout_height="@dimen/progressbar_height"
android:layout_centerInParent="true"
android:indeterminate="true"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
refresh_text is the TextView which is moving out of the visible region.
Solution
the issue is with relative layout use ConstraintLayout try this code
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:id="@+id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_empty"
android:layout_gravity="center" />
<TextView
android:id="@+id/empty_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingTop="12dp"
android:paddingRight="16dp"
android:textAlignment="center"
android:textColor="@color/data_color"
android:textSize="@dimen/text_medium"
android:gravity="center_horizontal" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:minHeight="40dp">
<TextView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:id="@+id/refresh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/refresh" />
<ProgressBar
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/progress"
android:layout_width="@dimen/progressbar_width"
android:layout_height="@dimen/progressbar_height"
android:indeterminate="true"
android:visibility="gone" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
Answered By - Hamid Raza Goraya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.