Android TableLayout change padding programmatic
How can I change the padding of a TableLayout programmatic. I try this code, but it does not wok. I get a java.lang.ClassCastException: android.widget.TableLayout$LayoutParams exception.
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);
If you're having a cast exception, try using the right class for it, i.e. TableLayout.MarginLayoutParams
instead of MarginLayoutParams
and LayoutParams
(which ones are you including?)
TableLayout.MarginLayoutParams destinationMarginLayout = new TableLayout.MarginLayoutParams(
精彩评论