Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在ConstraintLayout中,当我将视图的布局方向设置为";rtl";有些事情出错了。如何避免这种情况?_Android_Android Constraintlayout - Fatal编程技术网

Android 在ConstraintLayout中,当我将视图的布局方向设置为";rtl";有些事情出错了。如何避免这种情况?

Android 在ConstraintLayout中,当我将视图的布局方向设置为";rtl";有些事情出错了。如何避免这种情况?,android,android-constraintlayout,Android,Android Constraintlayout,介绍我的问题的示例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://

介绍我的问题的示例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"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/toBeUpdated"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layoutDirection="rtl"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@+id/guideline"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:text="@string/update_text_view"
        android:onClick="updateTextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_begin="274dp" />

</android.support.constraint.ConstraintLayout>

我想不出当内容更新时文本视图应该跳转的任何原因。我认为这是一个bug,它可能与不时出现的左/右和开始/结束混淆有关

您不显示屏幕截图,我无法确定您想要实现什么,但我认为您的解决办法是使用左/右而不是开始/结束文本视图,如下所示:

<TextView
    android:id="@+id/toBeUpdated"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layoutDirection="rtl"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintLeft_toRightOf="@+id/guideline"
    app:layout_constraintTop_toTopOf="parent" />


我已经试过了,视图不会像开始/结束时那样跳跃。

请用你的Minsdk版本更新你的问题好吗?文本有多长,你试图动态放入的文本?这并不重要。当它为0时,我希望它为1,反之亦然@RezaHamzehieI也有同样的问题,您是否找到了更优雅的解决方案,仍然使用start/end而不是right/left?不过您的解决方案对我来说效果很好。但这种跳跃仍然很神秘。Thanks@MohammadRezaHosseini不那么神秘。开始/结束优先于左/右,但当两者都允许时,错误会滑入。我认为这是一个bug,如果你这么想,应该向谷歌团队报告,如果它还没有报告的话。
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "example.com.testconstraintlayout"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
<TextView
    android:id="@+id/toBeUpdated"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layoutDirection="rtl"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintLeft_toRightOf="@+id/guideline"
    app:layout_constraintTop_toTopOf="parent" />