【问题标题】:How to set FrameLayout height to match one of the child component如何设置 FrameLayout 高度以匹配子组件之一
【发布时间】:2021-08-03 12:45:18
【问题描述】:

我有以下包含TextViewProgressBar 的框架布局。在某一特定时间,仅显示其中之一。 hideText 标志最初设置为 false。

   <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textview_detail_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@{model.text}"
            android:visibility="@{model.hideText}" />

        <ProgressBar
            android:id="@+id/progress_loader"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="@{!model.hideText}" />
    </FrameLayout>

TextView 中的文本是动态获取的,因此该组件的高度在运行前是未知的。当我将hideText 标志设置为true 时,框架布局的高度会缩小以匹配进度条。但是,我希望框架布局保持其初始高度(即TextView 的高度并在中间显示进度条。

有没有办法指定ProgressBarandroid:layout_height属性来匹配TextView的高度?

【问题讨论】:

  • 只是不要让textview_detail_titleGONE成为INVISIBLE

标签: android android-layout android-framelayout android-layout-weight android-layoutparams


【解决方案1】:

您需要将视图导入布局文件。

<data>
    <import type="android.view.View"/>
    ...
</data>

比对于文本来说:

android:visibility="@{model.hideText == true ? View.INVISIBLE : View.VISIBLE}"

对于 ProgressBar 这个:

android:visibility="@{model.hideText == true ? View.VISIBLE : View.INVISIBLE}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-25
    • 2016-03-01
    • 2012-05-14
    • 2016-11-27
    • 2015-11-11
    • 2023-03-23
    • 2012-08-18
    • 2012-03-02
    相关资源
    最近更新 更多