在anko DSL中相当于<fragment>标签
如何用Anko DSL等价物替换这个XML?
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> // more code here.... <fragment android:id="@+id/my_fragment" android:layout_width="340dp" android:layout_height="match_parent" android:layout_gravity="start" android:name="com.myapp.MyFragment" /> // more code here.... </LinearLayout>
安科版本:
UI { linearLayout { orientation= VERTICAL fragment { // error! name = "com.myapp.MyFragment" } }.lparams(width=..., height=...) }
似乎没有eqiuvalen在DSL中的片段标签。
谢谢!
目前在Anko中没有特别的功能,你可以使用Android API来做到这一点。
supportFragmentManager.beginTransaction().add(this.id, com.myapp.MyFragment()).commit()
请注意,您需要为您的linearLayout
设置一个id
,因为add
方法需要设置它。
- Kotlin Android视图绑定:findViewById vs Butterknife vs Kotlin Android扩展
- Android Studio – java.io.IOException:无法生成v1签名
- ArrayAdapter.clear kotlin
- Kotlin – 带多个标志语法的getPendingIntent
- EditText失去了重点TextTextChange
- Kotlin添加自定义监听器在Android上点击小部件
- Android Studio:即使在即时运行时按下运行应用程序,代码更改也不会反映出来
- 如何写while循环与在kotlin中的responseInputStream.read – (while((i = responseInputStream.read(byteContainer))
- Android – ViewDataBinding.inflate不会膨胀嵌套的自定义视图