I have the following framelayout containing a TextView
and ProgressBar
. At one given time, only one of them is shown. The hideText
flag is initially set to 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>
The text in the TextView
is fetched dynamically so the height of this component is unknown before runtime. When I set the hideText
flag to true
, The height of the frame layout shrinks to match the progress bar. However, I would like the frame layout to maintain it's initial height (ie that of the TextView
and display the progress bar in the middle.
Is there any way to specify the ProgressBar
's android:layout_height
property to match the TextView height?
You need import View to your layout file.
<data>
<import type="android.view.View"/>
...
</data>
And than For text make this:
android:visibility="@{model.hideText == true ? View.INVISIBLE : View.VISIBLE}"
And for ProgressBar this:
android:visibility="@{model.hideText == true ? View.VISIBLE : View.INVISIBLE}"