Android 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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您遇到强制转换异常,请尝试使用正确的类,即
TableLayout.MarginLayoutParams
而不是MarginLayoutParams
和LayoutParams
(哪些是你包括在内吗?)If you're having a cast exception, try using the right class for it, i.e.
TableLayout.MarginLayoutParams
instead ofMarginLayoutParams
andLayoutParams
(which ones are you including?)