layout_constrainedWidth无法正常工作 [英] layout_constrainedWidth not working properly
问题描述
我的ConstraintLayout中有EditText和TextView. TextView显示EditText的内容.
I’ve got EditText and TextView in my ConstraintLayout. TextView displays content of EditText.
在输入时,我需要EditText展开直到屏幕中间,然后是TextView跟随它并填充下半部分.
On input I need EditText to expand untill the middle of the screen and TextView to follow it and fill the second half.
我将准则设置为50%,并且对两个小部件都使用wrap_content和layout_constrainedWidth.
I set guideline at 50%, and use wrap_content и layout_constrainedWidth for both widgets.
这是我的xml:
<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="com.manualuser.android.polygon.MainActivity">
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:inputType="textNoSuggestions"
android:minWidth="1dp"
android:scrollHorizontally="true"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/guideline"
app:layout_constraintTop_toTopOf="parent"/>
<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="@+id/editText"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="@+id/editText"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
app:layout_constrainedWidth="true"
app:layout_constraintBaseline_toBaselineOf="@+id/editText"
app:layout_constraintEnd_toStartOf="@+id/textView"
app:layout_constraintStart_toEndOf="@+id/editText"/>
</HorizontalScrollView>
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5"/>
</android.support.constraint.ConstraintLayout>
我得到的是,当TextView到达屏幕末端时,它将取代EditText到左侧.
What I get is when TextView reaches end of the screen it supersedes EditText to the left.
当我将TextView layout_width设置为match_constraint时,它可以根据需要工作.但是,如何使它与wrap_content一起使用?
It works as needed when I set TextView layout_width to match_constraint. But how do I make it work with wrap_content?
推荐答案
我有一个非常相似的问题.
基本上我观察到的是,将app:layout_constraintHorizontal_bias
设置为0.0
时,它工作起来很奇怪.
I had a very similar issue.
Basically what I observed is that it works weird when used with app:layout_constraintHorizontal_bias
set to 0.0
.
所以,如果您更改
app:layout_constraintHorizontal_bias="0.0"
到
app:layout_constraintHorizontal_bias="0.001"
它应该起作用(至少对我有用)
It should work (at least it worked for me)
如果有时间,请报告为错误.即使在2.0.0-beta2
Please report it as a bug if you have time. It's an issue even in 2.0.0-beta2
这篇关于layout_constrainedWidth无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!