代码之家  ›  专栏  ›  技术社区  ›  Kingfisher Phuoc

重力在多种语言中不起作用

  •  0
  • Kingfisher Phuoc  · 技术社区  · 6 年前

    这是我的 TextView

    <TextView
        android:id="@+id/btnAgree"
        android:layout_height="56dp"
        android:layout_width="0dp"
        android:gravity="center"
        android:layout_marginBottom="21dp"
        android:foreground="?attr/selectableItemBackground"
        android:text="@string/label_gdpr_agree"
        android:textSize="14sp"
        android:textStyle="bold"
        android:background="@color/yellow_gdpr_button"
        app:layout_constraintBottom_toTopOf="@id/tvGdprPage"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        />
    

    问题是,它在许多情况下都能很好地工作 English ,但不是 Vietnamese 在里面 越南人 朗,只有中水平(上中)。有人有这个问题吗?下面的图片是在 越南人 .

    enter image description here

    2 回复  |  直到 6 年前
        1
  •  0
  •   PRATEEK BHARDWAJ    6 年前

    你应该把“相对布局”作为父布局。然后使用alignParentEnd属性来支持rtl。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
       <TextView
            android:id="@+id/btnAgree"
            android:layout_height="56dp"
            android:layout_width="0dp"
            android:gravity="center"
            android:layout_marginBottom="21dp"
            android:foreground="?attr/selectableItemBackground"
            android:text="@string/label_gdpr_agree"
            android:textSize="14sp"
            android:textStyle="bold"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginTop="@dimen/dp100"
            />
    
    
    </RelativeLayout>
    
        2
  •  0
  •   Nitin Gurbani    6 年前

    无法追踪你为什么会遇到这样的问题。

    下面提到的代码是我写的,效果非常好。

    <?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"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:id="@+id/btnAgreeEnglish"
            android:layout_height="56dp"
            android:layout_width="0dp"
            android:gravity="center"
            android:foreground="?attr/selectableItemBackground"
            android:text="This is my text. This is my text."
            android:textSize="14sp"
            android:textStyle="bold"
            android:background="@android:color/holo_blue_bright"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />
    
        <TextView
            android:id="@+id/btnAgreeVietnamese"
            android:layout_height="56dp"
            android:layout_width="0dp"
            android:gravity="center"
            android:layout_marginTop="30dp"
            android:foreground="?attr/selectableItemBackground"
            android:text="Đây là văn bản của tôi. Đây là văn bản của tôi."
            android:textSize="14sp"
            android:textStyle="bold"
            android:background="@android:color/holo_blue_bright"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/btnAgreeEnglish"
            app:layout_constraintEnd_toEndOf="parent" />
    
    </android.support.constraint.ConstraintLayout>
    

    我希望,这对您有所帮助,但如果您仍然面临任何此类问题,欢迎您回复。:-)

    推荐文章