【发布时间】:2015-07-11 00:50:51
【问题描述】:
我正在尝试在运行时将 TextView 添加到 GridLayout。由于没有设置 GridLayout 的单元格背景的属性,所以我设置 TextView 背景看起来像单元格背景在其边界处有笔划。我的问题是,在运行时将 TextView 添加到 Gridlayout 时, TextView 大小不 Stretching 等于 GridLayout Cell 。
在我设置的xml文件中:
<GridLayout
android:id="@+id/gridLay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alignmentMode="alignBounds"
android:columnCount="5"
android:columnOrderPreserved="false"
android:useDefaultMargins="false" >
<TextView
android:layout_gravity="fill"
android:background="@drawable/grid_lay_cell_bg"
android:padding="5dp"
android:text="Name"
android:textSize="14dp" />
</GridLayout>
它工作得很好,TextView 涵盖了完整的单元格大小,但是当我尝试在以下代码中添加它时:
TextView tv3 = new TextView(getActivity());
GridLayout.LayoutParams lp3 = new GridLayout.LayoutParams(GridLayout.spec(2, 1), GridLayout.spec(0, 1));
lp3.setGravity(Gravity.FILL);
tv3.setLayoutParams(lp3);
tv3.setGravity(Gravity.FILL);
tv3.setPadding(padd, padd, padd, padd);
tv3.setBackgroundResource(R.drawable.grid_lay_cell_bg);
tv3.setTextSize(16);
tv3.setText("Test");
gridLay.addView(tv3, lp3);
TextView 没有覆盖完整的单元格大小。
请给我一些提示,在Android运行时将TextView添加到GridLayout时如何拉伸TextView大小等于单元格大小。
【问题讨论】:
-
@Haresh Chhelana...谢谢你的回复,但这不是我要问的
标签: android textview android-gridlayout