我有一个TableLayout,它占据了设备屏幕宽度的一半。我想根据我放在TableRow中的文本的大小来调整它的TableRows高度。
我应该在我的XML描述中使用什么属性来做这件事,因为android:layout_height="wrap_content"对我没有帮助?
发布于 2012-11-19 19:00:22
利用TableLayout类的android:stretchColumns和android:shrinkColumns属性解决了这一问题。
发布于 2012-11-19 08:22:02
首先,您应该使用显示因子公式将其从dps转换为像素。
final float scale = getContext().getResources().getDisplayMetrics().density;
int trHeight = (int) (30 * scale + 0.5f);
int trWidth = (int) (67 * scale + 0.5f);
ViewGroup.LayoutParams layoutpParams = new ViewGroup.LayoutParams(trWidth, trHeight);
tableRow.setLayoutParams(layoutpParams);https://stackoverflow.com/questions/4679524
复制相似问题