日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android使用ConstraintLayout 加载RecyclerView数据显示不全

發(fā)布時間:2025/3/15 Android 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android使用ConstraintLayout 加载RecyclerView数据显示不全 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

今天學習KT的時候,發(fā)現(xiàn)的一個問題,現(xiàn)在做個筆記

在由于才學習kt,所以很多東西沒辦法想JAVA那樣順手,所以正在一步一步的填坑中。。。

先看問題:
我在List中添加了幾條個人數(shù)據(jù),然后再添加了20條數(shù)據(jù),這樣列表就能夠滑動,
但是呢,結(jié)果發(fā)現(xiàn)RecyclerView 只顯示了for循環(huán)的15條,第16條-20條都不見了


Activity的代碼:

class MainActivity : AppCompatActivity() {var testList = ArrayList<String>()lateinit var testAdapter: KtReAdapteroverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)initImage()initRecycView()}private fun initRecycView() {testList.add("側(cè)滑菜單功能界面")testList.add("TAB菜單功能界面")testList.add("ScrollingActivity功能界面")testList.add("FullscreenActivity功能界面")testList.add("SettingsActivity功能界面")for (i in 1..20) {testList.add("測試---"+i)}val mylayoutManager = LinearLayoutManager(this)re_view.layoutManager = mylayoutManagertestAdapter = KtReAdapter(this, this.testList)re_view.adapter = testAdapter} }

看到這個結(jié)果 我就納悶了,為啥后面的數(shù)據(jù)沒顯示呢, 之后我就在
Adapter里面打印日志,結(jié)果發(fā)現(xiàn)數(shù)據(jù)是加載出來了,但是,但是并沒有顯示

Log日志

然后就到了找問題的時候了,現(xiàn)在數(shù)據(jù)沒有問題 那么就是布局的問題了,我看了看布局,然后百度了一下 搜索了ConstraintLayout的屬性說明 以及其中的含義 發(fā)現(xiàn)里一些有用的信息

<androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/re_view"android:layout_width="match_parent"android:layout_height="wrap_content"app:layout_constraintTop_toBottomOf="@+id/img" />

我的RecyclerView的高度有問題 ,按照ConstraintLayout的屬性說明,如果我的RecyclerView要完全占滿下面的所有位置,可以把 高度設置為0,但是Y軸上面就要設置屬性,所以我又加了一句

app:layout_constraintBottom_toBottomOf="parent"

OK,問題解決,重新設置一下RecyclerView的屬性即可

<androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/re_view"android:layout_width="match_parent"//********** 修改的部分 *******android:layout_height="0dp"app:layout_constraintBottom_toBottomOf="parent"//********** 修改的部分 *******app:layout_constraintTop_toBottomOf="@+id/img" />

成功后的截圖:

總結(jié)

以上是生活随笔為你收集整理的Android使用ConstraintLayout 加载RecyclerView数据显示不全的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。