第一次在这里进行android编程。因此,我通过Anko布局进行了第二个活动,该布局具有一个imageView和2个textView作为名称和描述。但是这些textView没有显示。我认为代码看起来不错,但我不知道它仍然没有出现。有什么办法吗?谢谢。
-MainActivity
MainActivity类:AppCompatActivity(){
var items: MutableList<Item> = mutableListOf()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(activity_main)
initData()
club_list.layoutManager = LinearLayoutManager(this)
club_list.adapter = RecyclerViewAdapter(this,items){
startActivity(intentFor<SecondActivity>(forto to it.clubName, forto to clubDesc, forto to it.clubImage))
}
}
@SuppressLint()
private fun initData(){
val nameClub = resources.getStringArray(club_name)
val descClub = resources.getStringArray(club_desc)
val imageClub = resources.obtainTypedArray(club_image)
items.clear()
for (i in nameClub.indices) {
items.add(Item(nameClub[i], descClub[i], imageClub.getResourceId(i, 1)))
}
imageClub.recycle()
}
}
const val forto =“ com.my.app”
-SecondActivity
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
linearLayout {
orientation = LinearLayout.VERTICAL
val image = intent.getIntExtra(forto, 1)
imageView {
topPadding = dip(16)
imageResource = image
}.lparams(width = matchParent, height = dip(100)) {
gravity = Gravity.CENTER_HORIZONTAL
val namaClub = intent.getStringExtra(forto)
textView {
text = namaClub
textAlignment = View.TEXT_ALIGNMENT_CENTER
}.lparams(width = matchParent)
}
val clubDesc = intent.getStringExtra(forto)
verticalLayout {
textView {
text = clubDesc
padding = dip(16)
}.lparams(width = matchParent)
}
}
}
-数据类(如果需要)
@包裹 数据类项目(var clubName:字符串,var clubDesc:字符串,var clubImage:Int):可打包
答案 0 :(得分:0)
在第二个活动中,在imageView的“ lparams”块内有一个textview。我怀疑您是要在设置重力后关闭lparams。