开发者

Android TableLayout change padding programmatic

开发者 https://www.devze.com 2023-03-10 20:06 出处:网络
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.

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(
0

精彩评论

暂无评论...
验证码 换一张
取 消