Matt
Matt

Reputation: 5511

Android - Modifying layout values in XML

Is there a way to modify the value of a resource while assigning it in XML?

For example, this works fine:

android:layout_height="?attr/actionBarSize"

But I would like to double this value as its width:

// this obviously doesn't work
android:layout_width="?attr/actionBarSize * 2"

Is there some way to accomplish this?

Upvotes: 1

Views: 91

Answers (1)

broody
broody

Reputation: 707

You can do this programmatically.

LinearLayout layout = (LinearLayout) findViewById(R.id.yourlayout);
LayoutParams params = layout.getLayoutParams();

params.width *= 2;

Upvotes: 1

Related Questions