【发布时间】:2020-08-09 02:51:56
【问题描述】:
我有一个这样的 GridLayout
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:elevation="2dp"
app:cardCornerRadius="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:text="Famous People"
android:textSize="17sp"
android:textStyle="bold" />
<GridLayout
android:id="@+id/llFamousPeople"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="3"
android:alignmentMode="alignBounds"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:orientation="horizontal"
android:textSize="17sp" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
我正在像这样以编程方式设置 GridLayout 中的值
extra?.famous_people?.forEach {
val textView = TextView(this)
val gridparams = GridLayout.LayoutParams()
gridparams.apply {
height = GridLayout.LayoutParams.WRAP_CONTENT
width = GridLayout.LayoutParams.WRAP_CONTENT
}
textView.layoutParams = gridparams
val marginParams = textView.layoutParams as ViewGroup.MarginLayoutParams
marginParams.bottomMargin = 10
marginParams.topMargin = 10
marginParams.leftMargin = 10
marginParams.rightMargin = 10
textView.setPadding(5, 5, 5, 5)
textView.text = it
llFamousPeople.addView(textView)
}
第 3 列的名字被删掉了。任何帮助,将不胜感激。谢谢
【问题讨论】:
标签: android kotlin textview android-gridlayout