Android TableLayout更改填充程序化

时间:2011-06-03 22:09:37

标签: android padding tablelayout

如何更改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);

1 个答案:

答案 0 :(得分:0)

如果你有一个强制转换异常,请尝试使用正确的类,即TableLayout.MarginLayoutParams而不是MarginLayoutParamsLayoutParams(你包括哪些?)

TableLayout.MarginLayoutParams destinationMarginLayout = new TableLayout.MarginLayoutParams(