Below is the code of the item layout of gridview. In this, the layout_margin is there in the design panel but when I run the there is no margin. I tried to check other tags like the background and found that it was working. A similar problem is with the layout_weights of linear_layout, the are also not working. These were working fine without data binding. Can someone please help me out in resolving this? '''
<?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>
<variable
name="localEntry"
type="com.example.lo_cal.data.models.LoCalEntry" />
</data>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/small"
android:background="@color/colorAccent"
android:orientation="vertical">
<TextView
android:id="@+id/item_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:itemId="@{localEntry}"
tools:text="ID" />
<TextView
android:id="@+id/item_first_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{localEntry.firstName}"
tools:text="shashank" />
<TextView
android:id="@+id/item_second_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{localEntry.secondName}"
tools:text="mohabia" />
<TextView
android:id="@+id/item_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{localEntry.result}"
tools:text="100" />
</androidx.appcompat.widget.LinearLayoutCompat>
</layout>
'''
Data binding includes everything that ViewBinding has, so it wasn't designed to work side by side with View binding. The biggest issue is the naming conflict between the generated classes. Both ViewBinding and DataBonding would want to generate the class MainLayoutBinding for the layout main_layout. xml .
Databinding is really faster compared to findViewById and setText . Not only performance, It is also much faster and maintainable for mid, full-scale projects. As a side note, benefits include: performance.
You just have to import <import type="android. content. Context" /> in your xml data imports. Then, you can access context for your databinding simply with context .
I faced this problem when inflate the view. Previously,
mBinding = FragmentxxBinding.inflate(inflater);
After I change to
mBinding = FragmentxxBinding.inflate(inflater, container, false);
the problems solved, hope this can help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With