使用数据绑定后,视图边距不起作用 [英] View margin not working after using databinding

查看:108
本文介绍了使用数据绑定后,视图边距不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是gridview的项目布局代码。在这种情况下,layout_margin在设计面板中,但是在我运行时没有空白。我尝试检查其他标签(例如背景),发现它可以正常工作。
类似的问题是linear_layout的layout_weights也不起作用。没有数据绑定,它们工作正常。
有人可以帮我解决这个问题吗?
’’

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>

'''

推荐答案

膨胀视图时遇到了这个问题。
以前,

I faced this problem when inflate the view. Previously,

mBinding = FragmentxxBinding.inflate(inflater);

更改后

mBinding = FragmentxxBinding.inflate(inflater, container, false);

问题解决了,希望能对您有所帮助。

the problems solved, hope this can help.

这篇关于使用数据绑定后,视图边距不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆