[英]Strange TextView behaviour in ConstraintLayout
我有一個appin的詳細頁面布局。 它包含一個信息框,其中包含最重要的信息,傳記和回收者視圖以及演員正在播放的電影。但是當傳記很短時,它看起來就像這樣:
這不是自定義TextView的錯誤,因為同樣的奇怪行為也會發生在普通的TextView中。 任何人都知道如何解決這種奇怪的行為?
這是xml布局文件
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<android.support.v4.widget.NestedScrollView
android:id="@+id/detail_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/detail_app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.mt.moviesiwanttowatch.CustomToolbar
android:id="@+id/drawer_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</android.support.design.widget.AppBarLayout>
<android.support.constraint.ConstraintLayout
android:id="@+id/movie_overview_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:background="?attr/detail_card_2_color"
android:paddingLeft="@dimen/material_layout_keylines_horizontal_mobile_margin"
android:paddingRight="@dimen/material_layout_keylines_horizontal_mobile_margin"
android:paddingTop="@dimen/material_layout_keylines_horizontal_mobile_margin">
<android.support.v7.widget.CardView
android:id="@+id/info_holder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@+id/overview"
>
<RelativeLayout
android:id="@+id/basic_info_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/detail_card_1_color"
android:orientation="horizontal"
android:paddingBottom="@dimen/material_layout_keylines_horizontal_mobile_margin"
android:paddingLeft="56dp"
android:paddingRight="24dp">
<!-- Poster Area -->
<FrameLayout
android:id="@+id/poster_image_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true">
<!-- Default Image -->
<ImageView
android:id="@+id/poster_image_default"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
android:src="@drawable/default_poster"
android:visibility="gone"
tools:ignore="contentDescription" />
<com.mt.moviesiwanttowatch.ui.widget.ThemeIcon
android:id="@+id/poster_image_def"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/ic_add_alarm_white_48dp"
android:visibility="gone"
custom:iconColor="?attr/icon_color"
tools:ignore="contentDescription" />
<android.support.v7.widget.CardView
android:id="@+id/poster_image_holder"
android:layout_width="@dimen/detail_poster_width"
android:layout_height="@dimen/detail_poster_height"
android:layout_alignParentBottom="true"
android:layout_marginLeft="@dimen/material_layout_keylines_horizontal_mobile_margin"
android:layout_marginStart="@dimen/material_layout_keylines_horizontal_mobile_margin">
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/poster_image"
android:layout_width="@dimen/detail_poster_width"
android:layout_height="@dimen/detail_poster_height"
android:layout_alignParentBottom="true"
android:background="@color/default_image_background"
android:padding="1dp"
android:scaleType="centerCrop"
/>
</android.support.v7.widget.CardView>
<!-- Poster Image -->
</FrameLayout>
<!-- Text Area -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/poster_image_container"
android:gravity="center_vertical"
android:orientation="vertical">
<!-- Title -->
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="@+id/cast_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/material_layout_keylines_horizontal_mobile_margin"
android:lines="1"
android:textSize="@dimen/text_size_subheading"
custom:robotoType="bold"
tools:text="01 January 2016\n120 mins" />
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="@+id/cast_birthdy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/material_layout_vertical_spacing_between_content_areas"
android:lines="1"
android:textSize="@dimen/text_size_subheading"
custom:robotoType="bold"
tools:text="01 January 2016\n120 mins" />
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="@+id/cast_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/material_layout_vertical_spacing_between_content_areas"
android:lines="1"
android:textSize="@dimen/text_size_subheading"
custom:robotoType="bold"
tools:text="01 January 2016\n120 mins" />
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="@+id/cast_homepage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/material_layout_vertical_spacing_between_content_areas"
android:lines="1"
android:textSize="@dimen/text_size_subheading"
custom:robotoType="bold"
tools:text="01 January 2016\n120 mins" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<com.mt.moviesiwanttowatch.ui.widget.ThemeIcon
android:id="@+id/overview_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/ic_info_white_24dp"
app:iconColor="@color/accent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@+id/overview"
app:layout_constraintBottom_toBottomOf="@+id/overview"/>
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="@+id/overview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="56dp"
android:layout_marginTop="16dp"
android:text="@string/detail_header_overview"
android:textSize="16sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/info_holder"
app:layout_constraintBottom_toTopOf="@+id/movie_overview_value"
custom:robotoType="bold" />
<!-- Value -->
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="@+id/movie_overview_value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size_body2"
app:layout_constraintLeft_toLeftOf="@+id/overview"
app:layout_constraintRight_toRightOf="@id/info_holder"
app:layout_constraintTop_toBottomOf="@+id/overview_icon"
app:layout_constraintBottom_toTopOf="@+id/sidescroll"
custom:robotoType="regular"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/sidescroll"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/movie_overview_value"
/>
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.Coortextview-goes-behind-other-view-with-long-texts-constraintlayoutdinatorLayout>
</android.support.v4.widget.NestedScrollView>
</layout>
編輯:這個問題沒有重復https://stackoverflow.com/questions/42613994/textview-goes-behind-other-view-with-long-texts-constraintlayout,因為這個問題是關於間距行為而另一個問題是關於為什么長文本視圖隱藏在另一個視圖后面的原因,而短文本文本視圖不是
您可以嘗試使用LinearLayout
定位視圖,將此代碼放在CardView
下面:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.mt.moviesiwanttowatch.ui.widget.ThemeIcon
android:id="@+id/overview_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/ic_info_white_24dp"
app:iconColor="@color/accent"
/>
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="@+id/overview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="56dp"
android:layout_marginTop="16dp"
android:text="@string/detail_header_overview"
android:textSize="16sp"
custom:robotoType="bold" />
<!-- Value -->
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="@+id/movie_overview_value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size_body2"
custom:robotoType="regular"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/sidescroll"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
/>
</LinearLayout>
我認為這是因為您只是為textview的最頂端提供錨點,嘗試從上部和下部視圖的頂部和底部設置錨點。
最新的約束布局版本不存在此錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.