android - 使用数据绑定(bind)后查看边距不起作用

标签 android kotlin android-recyclerview data-binding android-viewholder

下面是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/

相关文章:

android - 以编程方式将 AppCompatActivity 显示为对话框

java - 如何在 SQLite 数据库中保存 Google Map 折线?

android - 为什么单击后退按钮时,许多Android应用程序中的闪光灯屏幕没有关闭?

unit-testing - Mockito never() 不与 andThen rxjava2 一起使用

android - 如何更改分配给 RecyclerView 中的 ImageButton 的矢量颜色?

android - 在 Android 中按下 Button 时连续触发事件

android - 具有普通 fragment 和支持 fragment 的 AppCompatActivity

android - 在 JetPack Composable 中观察 LiveData

java - CollapsingToolbarLayout 在 Recyclerview 下方留下空白

android - 将参数传递给 RequestListener Glide