MaNa Asked:2020-02-20 19:15:55 +0000 UTC2020-02-20 19:15:55 +0000 UTC 2020-02-20 19:15:55 +0000 UTC 不同列宽的表格(GridView) 772 有这样一个问题:有一个表(GridView),数据从数据库传输到该表中,并且所有单元格的大小相同。如何使第一列占据屏幕的一半,而其他两列则占全部剩余空间?如果这对于 GridView 是不可能的,那么可以使用哪些其他表格(但这样单元格是可点击的)? android 1 个回答 Voted Best Answer MaNa 2020-02-21T16:48:53Z2020-02-21T16:48:53Z 科特林: var COLS:Int = 3; var tblLayout = findViewById<View>(R.id.tableLayout)as TableLayout tblLayout.removeAllViews() var SCV=scrollView while(i</*количество строк*/) { var tableRow:TableRow = TableRow(this); tableRow.setLayoutParams( LayoutParaLayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT)); var j:Int=0 while(j<COLS) { var TV:TextView= TextView(this) TV.setTextColor(getResources().getColor(android.R.color.black)) TV.setTextSize(15.toFloat()) TV.setHeight(TV.getTextSize().toInt()*2) TV.setBackgroundResource(R.drawable.grid) TV.setText(/*данные*/) if((t % 3) == 0){ TV.setWidth((SCV.getWidth()/(1.3).toFloat()).toInt()) }else{ TV.setWidth((SCV.getWidth()-(SCV.getWidth()/(1.3).toFloat()).t())/2) } TV.setGravity(Gravity.CENTER) TV.setTag(t) TV.setOnClickListener { var position:Int= TV.getTag() as Int//номер ячейки } tableRow.addView(TV,j) t++ j++ } tblLayout.addView(tableRow,i) i++ } } XML: <ScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_weight="60" android:orientation="vertical" android:background="#ffffff" android:layout_height="0dp"> <TableLayout android:id="@+id/tableLayout" android:layout_width="match_parent" android:layout_height="match_parent"/> </ScrollView>
科特林:
XML: