Android ConstraintLayout TextView退出屏幕
正如你在图片中看到的,文字从墙上脱落了。这是一个非常奇怪的行为,我认为这是一个错误 下面是一个屏幕截图: 以下是标题xml:Android ConstraintLayout TextView退出屏幕,android,textview,android-constraintlayout,Android,Textview,Android Constraintlayout,正如你在图片中看到的,文字从墙上脱落了。这是一个非常奇怪的行为,我认为这是一个错误 下面是一个屏幕截图: 以下是标题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="ht
<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="wrap_content"
android:background="?android:attr/windowBackground"
android:orientation="vertical">
<TextView
android:id="@+id/street_name"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginStart="15dp"
android:text="street name"
android:textColor="?AppTheme.InformationText"
android:textSize="14sp"
android:textStyle="bold"
android:gravity="center"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="19dp"
android:layout_marginLeft="0dp"
app:layout_constraintWidth_default="wrap"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="@+id/guideline29"
app:layout_constraintTop_toTopOf="@+id/guideline37"
app:layout_constraintRight_toLeftOf="@+id/guideline30"
app:layout_constraintHorizontal_bias="0.605"
app:layout_constraintVertical_bias="0.0"/>
<ImageView
android:id="@+id/street_view_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:padding="6dp"
android:scaleType="fitCenter"
tools:layout_constraintLeft_creator="1"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="@+id/country_flag_image"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintRight_toLeftOf="@+id/guideline29"
android:layout_marginRight="8dp"
app:layout_constraintTop_toTopOf="@+id/guideline37"
android:layout_marginTop="8dp"/>
<ImageView
android:id="@+id/country_flag_image"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1"
/>
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/exit_image"
android:layout_width="46dp"
android:layout_height="46dp"
android:layout_marginBottom="8dp"
android:layout_marginRight="-4dp"
android:src="@drawable/exit_custom"
app:border_color="#FF000000"
app:layout_constraintBottom_toBottomOf="@+id/street_view_image"
app:layout_constraintRight_toRightOf="@+id/street_view_image"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintRight_creator="1"
/>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guideline29"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5"/>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guideline30"
app:layout_constraintGuide_begin="395dp"
android:orientation="vertical"/>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guideline37"
app:layout_constraintGuide_begin="8dp"
android:orientation="horizontal"/>
</android.support.constraint.ConstraintLayout>
但我认为这与此无关。
该设备是三星Note4,搭载安卓6.0.1。在android Studio 2.3.3中使用ConstraintLayout版本com.android.support.constraint:constraint layout:1.0.2
对于您的
,您应该使用android:layout\u width=“0dp”
和android:layout\u height=“wrap\u content”
,这样看起来像:
<TextView
android:id="@+id/street_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:text="street name"
android:textColor="?AppTheme.InformationText"
android:textSize="14sp"
android:textStyle="bold"
android:gravity="center"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="19dp"
android:layout_marginLeft="0dp"
app:layout_constraintWidth_default="wrap"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="@+id/guideline29"
app:layout_constraintTop_toTopOf="@+id/guideline37"
app:layout_constraintRight_toLeftOf="@+id/guideline30"
app:layout_constraintHorizontal_bias="0.605"
app:layout_constraintVertical_bias="0.0"/>
为街道名称设置android:layout\u width=“0dp”
。这将导致它匹配约束,并应使其保持在边界内
不工作<代码>街道名称
受指南30
在395dp
右侧的约束。395dp
是否在屏幕右侧?只需将文本视图连接到右侧,一切正常。当您使用约束将视图附加到另一个视图或父视图时,应使用所有4个约束。添加layconstraintEnd\u-toEndOf
app:layout\u constraintEnd\u toEndOf=“parent”
和宽度0dp
android:layout_width=“0dp”
仅设置宽度0dp不起作用使用app:layou constraintEnd\u toEndOf
而不是app:layout\u constraintRight\u toRightOf
因为在某些情况下,正确或正确可能显示错误
并使用Start\u toStartOf
而不是Left\u toLeft
也像其他人说的setandroid:layout\u width=“0dp”
0dp
表示匹配约束不起作用。我想了一会儿,安卓:gravity=“center”
是个小丑,但它不起作用。安卓:layout\u width=“0dp”已经设置好了。你是从哪里得到359dp的?@Erik你有没有检查过guideline30,看它是否脱离屏幕?哇,当我把guideline30放在procentare 80%时,它工作了…谢谢,有这么多的变量…谢谢你带我走过这段路…对于仍然在这个问题上的人,答案是:谢谢你的代码。我不熟悉安卓系统。这对我有帮助。!
<TextView
android:id="@+id/street_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:text="street name"
android:textColor="?AppTheme.InformationText"
android:textSize="14sp"
android:textStyle="bold"
android:gravity="center"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="19dp"
android:layout_marginLeft="0dp"
app:layout_constraintWidth_default="wrap"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="@+id/guideline29"
app:layout_constraintTop_toTopOf="@+id/guideline37"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.605"
app:layout_constraintVertical_bias="0.0"/>