How to set visibility for include layout in databinding

How to set visibility for include layout in databinding - Hello friend inabnomaniiyaha, In the article that you read this time with the title How to set visibility for include layout in databinding, we have prepared this article well for you to read and take information in it. hopefully the contents of the post Artikel android-example,what we write you can understand. Alright, happy reading.

Judul : How to set visibility for include layout in databinding
link : How to set visibility for include layout in databinding

Baca juga


How to set visibility for include layout in databinding

Although Android offers a variety of widgets to provide small and re-usable interactive elements, you might also need to re-use larger components that require a special layout. To efficiently re-use complete layouts, you can use the <include/> and <merge/> tags to embed another layout inside the current layout.

Reusing layouts is particularly powerful as it allows you create reusable complex layouts. For example, a yes/no button panel, or custom progress bar with description text. It also means that any elements of your application that are common across multiple layouts can be extracted, managed separately, then included in each layout. So while you can create individual UI components by writing a custom View, you can do it even more easily by re-using a layout file.

Solution:

dataBinding.regPhone.getRoot().setVisibility(View.GONE);

dataBinding.regEmail.getRoot().setVisibility(View.VISIBLE);

On the top layout, declare the boolean or an observable field whose value toggle the visibility of the included layout. Then remember to give the included layout an id else it wont work

<?xml version="1.0" encoding="utf-8"?>

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

    <data>

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

        <variable

            name="show"

            type="Boolean" />

    </data>

    <androidx.constraintlayout.widget.ConstraintLayout

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        tools:background="@color/colorPrimary">

        <include layout="@layout/progress"

            android:id="@+id/progress"

            android:visibility="@{show?View.VISIBLE:View.GONE}"/>

    </androidx.constraintlayout.widget.ConstraintLayout>

</layout>



That's the articleHow to set visibility for include layout in databinding

That's it for the article How to set visibility for include layout in databinding this time, hopefully can be useful for all of you. well, see you in another article post.

You are now reading the articleHow to set visibility for include layout in databinding with link addresshttps://inabnonapudyawanabing.blogspot.com/2021/07/how-to-set-visibility-for-include.html

0 Response to "How to set visibility for include layout in databinding"

Post a Comment

Tips Tricks for Android Phone

Tips & Tricks for Android Phone is a free android app and Collection of Tips and Tricks related to using your android mobile device lik...