相关疑难解决方法(0)

定义自定义attrs

我需要实现自己的属性,如in com.android.R.attr

在官方文档中找不到任何内容,因此我需要有关如何定义这些attrs以及如何在我的代码中使用它们的信息.

android android-resources android-attributes

449
推荐指数
4
解决办法
23万
查看次数

Jetpack Compose 预览中的 ViewDataBinding XML 文件

我无法在 Jetpack Compose 版本 1.0.5 中预览带有数据的 ViewDataBinding

我设法使用:

  1. 没有<layout>标签的Xml 文件感谢:/sf/answers/4691181141/

片段.kt

@Preview
@Composable
fun PreviewExample() {
    AndroidViewBinding(MyViewBinding::inflate)
}
Run Code Online (Sandbox Code Playgroud)

my_view.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="wrap_content">

    <TextView
            android:id="@+id/tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
  1. 带有<layout>标签但没有<data>标签的 Xml 文件,感谢:/sf/answers/4595762811/

片段.kt

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="wrap_content">

    <TextView
            android:id="@+id/tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

my_view_with_layout_tags.xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/text_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout> …
Run Code Online (Sandbox Code Playgroud)

xml android android-databinding android-jetpack-compose

12
推荐指数
0
解决办法
2014
查看次数