Tag: layout inflater

Inflator(root = null)布局破坏和Inflator(parentView = obj)无法设置位置

为了学习Kotlin和Android,我开始一个项目。 这是一个小发射器,但现在我有一个问题。 我的问题: A)当我用root:ViewGroup null调用Inflater.inflate时,我可以通过调用viewGroup.addView(v,postion)在根上的每个位置添加我的视图。 但我的布局被破坏,我的孩子的大小有错误的宽度。 val inflater = activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater val child = inflater.inflate(resource, null, true) viewGroup.addView(child, position) B)当我用root:ViewGroup父母调用Inflater.inflate时,我有我想要的布局,但我不能在视图(List)中决定我的孩子的位置。 val inflater = activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater val child = inflater.inflate(resource, viewGroup, true) 题: 在A)有可能从父视图设置布局设置我的孩子 在B)可以在父视图中从我的孩子设置位置 布局 父母是一个GridLayout,它显示最大宽度上的图标取决于确定的列。 孩子布局 如果你知道这个项目更好的设计/解决方案。 我很高兴学习新东西并实施。 谢谢你的时间

Android – ViewDataBinding.inflate不会膨胀嵌套的自定义视图

我真的难住Android的视图通胀问题。 我看了其他示例代码使用android.databinding,我似乎无法理解为什么这不起作用。 任何有Android的经验的人可以提供一些建议? 我创建了一个简单的自定义视图: class TestView(context: Context) : View(context) { private var testCallBack: TestCallback? = null fun setTestCallback(callback: TestCallback) { testCallBack = callback } interface TestCallback { fun test() } } 然后把它包含在一个简单的布局中: <?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"> <android.support.constraint.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".application.home.HomeActivity"> <com.test.TestView android:id="@+id/testView" android:layout_width="match_parent" android:layout_height="match_parent"/> </android.support.constraint.ConstraintLayout> </layout> 然后我膨胀我的片段onCreateView方法的布局,并使用视图绑定库,尝试设置我的自定义视图的回调: class TestFragment : TiFragmentBase<TiPresenterHolder, TiView>(), […]

将多个自定义LinearLayouts与按钮添加到ListView项目

我有一个相关的问题。 有人询问有关添加多个自定义LinearLayouts编程到ListView项目,这几乎是我需要做的。 在这个问题中,作者在LinearLayout中有TextViews。 我有一个按钮(和一些其他),当我点击这个按钮,我想膨胀一个新的LinearLayout下这个只需点击按钮。 如何获得当前的LinearLayout位置,所以我可以在它下面添加新的LinearLayout? 现在我在列表底部添加新的LinearLayout。