gpt4 book ai didi

java - RecyclerView 在 Groupie 中不可见 (Kotlin)

转载 作者:行者123 更新时间:2023-12-02 05:26:09 32 4
gpt4 key购买 nike

我正在尝试为我的 RecylerView 使用 Groupie 库(版本 2.1.0)。在我原来的应用程序中, View 根本不可见。我决定制作一个虚拟应用程序来解决我的问题,但我无法让 View 可见。我觉得解决方案可能很简单,因为这个库很容易使用。

MainActivity.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:

<?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 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(应用程序)

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'
}

最佳答案

我明白了。我忘记在 RecyclerView xml block 中添加布局管理器:app:layoutManager="android.support.v7.widget.LinearLayoutManager"

关于java - RecyclerView 在 Groupie 中不可见 (Kotlin),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56230707/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com