gpt4 book ai didi

android - Top_toBottomof 在 constraintlayout 中不起作用。如何在Constraint布局中使用Top_toBottomof?

转载 作者:行者123 更新时间:2023-11-29 14:57:39 24 4
gpt4 key购买 nike

我有以下布局:

    <?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 时,它会占据全屏而不是底部的左屏幕。这意味着它也会覆盖第一个卡片 View 并到达父/屏幕的顶部。那么在这种情况下,为什么设置约束 toptobottomof 不起作用,我怎样才能让它起作用?据我所知,toptobottomof 确保您的第二个 View 将始终保持在第一个 View 的下方,在这种情况下这是行不通的。

问题 2:如果我保持布局不变,那么问题是折线图根本没有扩展。它将整个图表高度压缩到包装内容高度中。它的行为不像它需要更多空间,因为这是 wrap_content 属性的用途,而是将图表本身限制在可用高度并且根本不扩展 cardview 高度。

请帮我解决这些问题。

最佳答案

将 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">

更新要实现 ScrollView ,请使用 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">

然后像这样从第二个 cardview 中删除这个 app:layout_constraintEnd_toEndOf="parent"

<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"
>

关于android - Top_toBottomof 在 constraintlayout 中不起作用。如何在Constraint布局中使用Top_toBottomof?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59261354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com