You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

RTL模式下ConstraintLayout中子View超出屏幕的问题求助

问题描述

我的布局文件如下:

<!-- activity_main.xml -->
<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">

    <RelativeLayout
        android:id="@+id/rl_next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="58dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <ImageView
            android:id="@+id/iv_bg"
            android:layout_width="136dp"
            android:layout_height="60dp"
            android:src="@drawable/bg_next_img" />

        <ImageView
            android:id="@+id/iv_arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@drawable/arrow" />
    </RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

涉及的Drawable文件如下:

  1. arrow.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="27dp"
    android:height="22dp"
    android:autoMirrored="true"
    android:viewportWidth="27"
    android:viewportHeight="22">

    <path
        android:fillColor="#ffffff"
        android:fillType="evenOdd"
        android:pathData="M17.09,21.036L26.278,11.848C26.747,11.38 26.747,10.62 26.278,10.151L17.09,0.964L15.393,2.661L22.532,9.8L0.492,9.8L0.492,12.2L22.532,12.2L15.393,19.339L17.09,21.036Z" />

</vector>

箭头已设置autoMirrored属性,且AndroidManifest.xml中已开启android:supportsRtl="true"。

  1. bg_next_img.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid
        android:color="#0066FF"/>
    <corners
        android:radius="100dp" />
</shape>

LTR语言模式下布局显示正常,但切换至希伯来语等RTL语言并重启应用后,箭头消失。通过布局检查器发现箭头的x坐标为-49,已超出屏幕范围。

已尝试方案

将rl_next的宽度设置为固定值136dp后,问题解决。

疑问

该问题仅在ConstraintLayout 2.1.4版本中出现,使用传统RelativeLayout未复现此问题,恳请协助排查根因。


内容的提问来源于stack exchange,提问作者Yatung Yü

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 11:05:19