我的布局如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical">
<include layout="@layout/toolbar_with_filter_back" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/banner"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="0dp" />
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="165dp" />
<android.support.v7.widget.CardView
android:id="@+id/win_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_5sdp"
android:elevation="@dimen/_8sdp"
app:cardCornerRadius="@dimen/_10sdp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
app:layout_constraintTop_toBottomOf="@+id/guideline">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/_10sdp">
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:gravity="center"
android:scaleType="fitXY"
app:cardCornerRadius="8dp"
app:cardPreventCornerOverlap="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/exec_business_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:scaleType="fitXY"
android:src="@drawable/icon_dairy" />
<TextView
android:id="@+id/exec_business_iconname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/exec_card_second_title"
android:fontFamily="@font/boutrosasma_regular"
android:gravity="center"
android:text="Foods"
android:textColor="@color/white"
android:textSize="@dimen/text_size_h" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="@+id/tvRname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:fontFamily="@font/boutrosasma_bold"
android:gravity="center"
android:text="@string/exe_size"
android:textColor="@color/exec_card_second_title"
android:textSize="@dimen/text_size_h_valve"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/fb_sr_bu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:fontFamily="@font/boutrosasma_regular"
android:gravity="center"
android:text="SR"
android:textColor="@color/exec_card_size_val_color"
android:textSize="@dimen/text_size_h"
android:textStyle="bold" />
<TextView
android:id="@+id/fb_size_val_bu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/_5sdp"
android:ellipsize="end"
android:fontFamily="@font/boutrosasma_bold"
android:gravity="center"
android:text="56.9"
android:textColor="@color/exec_card_size_val_color"
android:textSize="@dimen/_14ssp"
android:textStyle="bold" />
<TextView
android:id="@+id/fb_bn_bu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:fontFamily="@font/boutrosasma_regular"
android:gravity="center"
android:text="BN"
android:layout_marginLeft="@dimen/_5sdp"
android:textColor="@color/exec_card_size_val_color"
android:textSize="@dimen/text_size_h"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/layer_5" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="@+id/tvgrowth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:fontFamily="@font/boutrosasma_bold"
android:gravity="center"
android:text="@string/exe_growth"
android:textColor="@color/exec_card_second_title"
android:textSize="@dimen/text_size_h_valve"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="@+id/fb_growth_bu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:fontFamily="@font/boutrosasma_bold"
android:gravity="center"
android:text="+7.0%"
android:textColor="@color/exec_growth_val_color"
android:textSize="@dimen/_14ssp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/card_topplayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_5sdp"
android:elevation="@dimen/_8sdp"
app:cardCornerRadius="@dimen/_10sdp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
app:layout_constraintTop_toBottomOf="@+id/win_card"
app:layout_constraintEnd_toEndOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/top_player_back"
android:padding="@dimen/_10sdp">
<TextView
android:id="@+id/top_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/boutrosasma_bold"
android:text="@string/business_unit_top"
android:textColor="@color/exec_card_size_val_color" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:src="@drawable/orientation" />
</RelativeLayout>
<com.github.mikephil.charting.charts.LineChart
android:layout_margin="@dimen/_5sdp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/business_lineChart"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
问题1 : 当我将第二个Cardview高度设置为match_parent时,它将采用全屏模式,而不是底部的左侧屏幕。这意味着它将同时覆盖第一个卡片视图,并到达父/屏幕顶部。所以在这种情况下,为什么设置约束toptobottomof不起作用,我如何使其起作用?据我所知toptopbottomof确保您的第二个视图将始终保持低于第一个视图,在这种情况下不起作用。
问题2: 如果我保持原样,那么问题是LineChart根本没有扩展。它将整个图表高度压缩为换行内容高度。并不是表现出它需要更多空间,因为这是wrap_content属性的用途,它只是将图表本身限制为可用高度,并且根本没有扩展cardview的高度。
请帮助我解决这些问题。
答案 0 :(得分:5)
将android.support.v7.widget.CardView的高度更改为0dp
,将宽度更改为0dp
并使用app:layout_constraintBottom_toBottomOf="parent"
这将使高度填充到父级
添加这些
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
示例
<androidx.cardview.widget.CardView
android:id="@+id/card_topplayer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="@dimen/_5sdp"
android:elevation="@dimen/_8sdp"
app:cardCornerRadius="@dimen/_10sdp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/win_card">
更新 要实现滚动视图,请使用fillviewport = true
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:fillViewport = "true"
android:layout_height="0dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
然后像这样从第二个app:layout_constraintEnd_toEndOf="parent"
删除此cardview
<android.support.v7.widget.CardView
android:id="@+id/card_topplayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_5sdp"
android:elevation="@dimen/_8sdp"
app:cardCornerRadius="@dimen/_10sdp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
app:layout_constraintTop_toBottomOf="@+id/win_card"
>