[英]RecyclerView not Visible with Groupie (Kotlin)
I'm trying to use the Groupie library (version 2.1.0) for my RecylerView.我正在尝试将 Groupie 库(2.1.0 版)用于我的 RecylerView。 In my original app, the view would not be visible at all.在我原来的应用程序中,视图根本不可见。 I decided to make a dummy app to resolve my issue, and I just cannot get the view to be visible.我决定制作一个虚拟应用程序来解决我的问题,但我无法看到视图。 I feel the solution may be simple since this library is simple to use.我觉得解决方案可能很简单,因为这个库很容易使用。
MainActivity.kt:主活动.kt:
package com.dmelton.test
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import com.xwray.groupie.GroupAdapter
import com.xwray.groupie.Item
import com.xwray.groupie.ViewHolder
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val adapter = GroupAdapter<ViewHolder>()
adapter.add(Test())
adapter.add(Test())
adapter.add(Test())
new_recyclerView.adapter = adapter
}
}
class Test: Item<ViewHolder>() {
override fun bind(viewHolder: ViewHolder, position: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getLayout(): Int {
return R.layout.individual_service
}
}
activity_main.xml:活动_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:layout_width="395dp"
android:layout_height="715dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" android:id="@+id/new_recyclerView"/>
</android.support.constraint.ConstraintLayout>
individual_service.xml:个人服务.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="@+id/imageView_service"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@android:color/holo_blue_dark"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@android:drawable/ic_menu_preferences" />
<TextView
android:id="@+id/textView_service_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="8dp"
android:text="Service Name"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/imageView_service"
app:layout_constraintStart_toEndOf="@+id/imageView_service"
app:layout_constraintTop_toTopOf="@+id/imageView_service" />
<TextView
android:id="@+id/textView_service_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Status"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/imageView_service"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView_service_name"
app:layout_constraintTop_toTopOf="@+id/imageView_service" />
</android.support.constraint.ConstraintLayout>
build.gradle (app) build.gradle(应用程序)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.dmelton.test"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.xwray:groupie:2.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
}
I figured it out.我想到了。 I forgot to add the Layout Manager in my RecyclerView xml block: app:layoutManager="android.support.v7.widget.LinearLayoutManager"
我忘了在我的 RecyclerView xml 块中添加布局管理器: app:layoutManager="android.support.v7.widget.LinearLayoutManager"
你需要在你的布局文件中添加这个: app:layoutManager="android.support.v7.widget.LinearLayoutManager
加上你还需要添加
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.