下面是gridview的item布局代码。在此,layout_margin 在设计面板中,但是当我运行时没有边距。我试图检查其他标签,如背景,发现它正在工作。
类似的问题是linear_layout的layout_weights,也不起作用。这些在没有数据绑定(bind)的情况下工作正常。
有人可以帮我解决这个问题吗?
'''
<?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>
'''
最佳答案
我在膨胀 View 时遇到了这个问题。
之前,
mBinding = FragmentxxBinding.inflate(inflater);
在我更改为mBinding = FragmentxxBinding.inflate(inflater, container, false);
问题已解决,希望对您有所帮助。
关于android - 使用数据绑定(bind)后查看边距不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60792230/