TopTobottomof无法在约束布局中工作

问题描述 投票:0回答:1

我有以下布局:

<?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.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>

</LinearLayout>

问题1:当我将第二个Cardview高度设置为match_parent时,它将采用全屏模式,而不是底部的左侧屏幕。这意味着它将同时覆盖第一个卡片视图,并到达父/屏幕顶部。所以在这种情况下,为什么设置约束toptobottomof不起作用,我如何使其起作用?据我所知toptopbottomof确保您的第二个视图将始终保持低于第一个视图,在这种情况下不起作用。

问题2:如果我保持原样,那么问题是LineChart根本没有扩展。它将整个图表高度压缩为换行内容高度。它并不是表现出需要更多的空间,因为这是wrap_content属性的用途,它只是将图表本身限制为可用的高度,并且根本没有扩展cardview的高度。

这里是我将cardview设置为与父项匹配时的展开视图:enter image description here

这是我需要的视图,但也要与屏幕左侧的其余高度相适应:enter image description here请帮助我解决这些问题。

android android-constraintlayout mpandroidchart
1个回答
0
投票

将android.support.v7.widget.CardView的高度更改为0dp这将使高度填充到父级

  <android.support.v7.widget.CardView
            android:id="@+id/card_topplayer"
            android:layout_width="match_parent"
            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_constraintTop_toBottomOf="@+id/win_card"
            app:layout_constraintEnd_toEndOf="parent">
© www.soinside.com 2019 - 2024. All rights reserved.