【问题标题】:Recyclerview tools:listitem= not work on androidx Api version 30Recyclerview 工具:listitem= 不适用于 androidx Api 版本 30
【发布时间】:2020-07-26 06:01:34
【问题描述】:

所以我在Android studio version 3.6.3 上制作 Recyclerview,并使用 tools:listitem= 显示我的 Recyclerview 布局,当我运行模拟器时,没有出现在设计结果中,我使用 android API 版本 30 和 android studio 版本 3.6 .3,我使用 Kotlin 编程语言来创建我的 Recyclerview。

这是我的 main_activity.xml :

<androidx.recyclerview.widget.RecyclerView 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:padding="4dp"
    android:clipToPadding="false"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:listitem="@layout/example_item"/>

这是我的 example_item.xml :

<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/image_view"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:src="@drawable/abdulhalim" />

    <TextView
        android:id="@+id/text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toEndOf="@id/image_view"
        android:layout_toRightOf="@id/image_view"
        android:text="Line 1"
        android:textColor="#000000"
        android:textSize="18dp"
        android:textStyle="bold" />


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/text_view"
        android:layout_toEndOf="@id/image_view"
        android:text="Line 2"
        android:layout_toRightOf="@id/image_view" />

</RelativeLayout>

这是我的 MainAcitivity.kt :

class MainActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)


}

}

这是我添加 tools:listitem=添加时的结果

【问题讨论】:

    标签: android android-studio kotlin android-recyclerview sdk


    【解决方案1】:

    将您的父布局更改为LinearLayout

    <LinearLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">
    
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:padding="4dp"
        android:clipToPadding="false"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:listitem="@layout/example_item"/>
           </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 2019-10-06
      • 1970-01-01
      • 2019-06-15
      • 1970-01-01
      • 2019-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多