如何更改TableLayout程序化的填充。我尝试这个代码,但它没有尝试。我得到一个java.lang.ClassCastException:android.widget.TableLayout $ LayoutParams异常。
TextView destinationView = (TextView) view.findViewById(R.id.departure_destination);
destinationView.setText(departure.destination.name);
TableLayout destinationTimeTable = (TableLayout)
view.findViewById(R.id.destination_time_table);
int extraLength = line.length() > 3 ? line.length() - 3 : 0;
LayoutParams destinationPaddingLayout = new
LayoutParams(destinationTimeTable.getLayoutParams());
destinationTimeTable.setPadding(new Float(getResources().getDimension(R.dimen.destination_padding_left)
+ getResources().getDimension(R.dimen.destination_padding_extra) * extraLength).intValue(),
destinationPaddingLayout.topMargin, destinationPaddingLayout.rightMargin,
destinationPaddingLayout.bottomMargin);
答案 0 :(得分:0)
如果你有一个强制转换异常,请尝试使用正确的类,即TableLayout.MarginLayoutParams
而不是MarginLayoutParams
和LayoutParams
(你包括哪些?)
TableLayout.MarginLayoutParams destinationMarginLayout = new TableLayout.MarginLayoutParams(