6

Hướng dẫn trong ConstraintLayout có hỗ trợ RTL không? Tôi đang tạo một View có hình ảnh tiểu sử và thông tin người dùng ở bên phải. Tôi muốn hình ảnh chiếm 30% chiều rộng trong khi tên người dùng và chi tiết chiếm 70%. Đây có phải là trường hợp sử dụng hợp lệ cho Nguyên tắc không? Tôi biết các triển khai khác nhưng tôi đã tự hỏi liệu các nguyên tắc có thể được sử dụng ở đây hay không. Vấn đề tôi đang phải đối mặt là phương châm vẫn còn trong vị trí của nó ở bên trái sau khi thay đổi thiết bị ngôn ngữ sang ngôn ngữ RTLHướng dẫn trong hỗ trợ ConstraintLayout RTL

screenshot

Đây là xml:

<?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"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="80dp" 
     android:layout_height="80dp" 
     android:layout_marginStart="16dp" 
     android:layout_marginTop="16dp" 
     android:background="@color/colorPrimary" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <TextView 
     android:id="@+id/textView5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="24sp" 
     tools:text="Full Name" 
     app:layout_constraintTop_toTopOf="@+id/imageView" 
     app:layout_constraintStart_toEndOf="@+id/guideline2" /> 

    <TextView 
     android:id="@+id/textView6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="14sp" 
     tools:text="Android Developer" 
     app:layout_constraintBottom_toBottomOf="@+id/imageView" 
     app:layout_constraintStart_toEndOf="@+id/guideline2" /> 

    <android.support.constraint.Guideline 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/guideline2" 
     android:orientation="vertical" 
     app:layout_constraintGuide_percent="0.30" /> 


</android.support.constraint.ConstraintLayout> 

Trả lời

6

Có vẻ như nhóm Android đã bỏ lỡ vấn đề này.

Phần trăm chỉ được tính từ bên trái.

Vì vậy, để hỗ trợ RTL bạn có thể khai báo một hằng số trong các giá trị/dimens.xml, ví dụ:

<resources> 
    <item name="my_percent" format="float" type="dimen">0.3</item> 
</resources> 

Và ghi đè giá trị này với tập tin 100-mypercent trong values-ldrtl/dimens.xml của nó.

<resources> 
    <item name="my_percent" format="float" type="dimen">0.7</item> 
</resources> 

Sử dụng nó:

<android.support.constraint.Guideline 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/guideline2" 
    android:orientation="vertical" 
    app:layout_constraintGuide_percent="@dimen/my_percent" /> 
  • Nếu bạn muốn viết lại một phiên bản bố trí đầy đủ cho RTL, bạn có thể bỏ qua khía cạnh tuyên bố, và sử dụng layout-ldrtl/ thư mục cho các phiên bản RTL.
+1

Cảm ơn, tôi vừa kiểm tra trình theo dõi vấn đề và thấy nó đã được báo cáo: https://issuetracker.google.com/issues/38101983 – Ibrahim

+0

Cảm ơn, tôi cũng sẽ theo dõi nó. – auval

+2

Vấn đề được giải quyết chính thức trong ConstraintLayout 1.1.0 beta 3 https://androidstudio.googleblog.com/2017/10/constraintlayout-110-beta-3-is-now.html – Ibrahim

Các vấn đề liên quan