所以我在我的 Recyclerview 上Android studio version 3.6.3显示tools:listitem=我的 Recyclerview 布局,当我运行我的模拟器时,没有出现在设计结果中,我使用 android API 版本 30 和 android studio 版本 3.6.3,我使用 Kotlin 编程语言创建我的回收站视图。
这是我的 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"/>
</androidx.recyclerview.widget.RecyclerView>
这是我的 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>
</androidx.cardview.widget.CardView>
这是我的 MainAcitivity.kt :
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
