Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I do calculation inside dimens.xml?

Tags:

android

I just wondering can I do some calculations inside dimens.xml? I have tried it but doesn't work:

dimens.xml

<dimen name="wrap_content">-2dp</dimen>

<dimen name="width">@dimen/wrap_content * 0.5</dimen>
<dimen name="height">@dimen/wrap_content * 0.5</dimen>

my_layout.xml

<include
    android:id="@+id/main_right_menu_layout"
    android:layout_width="@dimen/width"
    android:layout_height="@dimen/height"
    layout="@layout/main_right_menu_layout" />
like image 304
Rendy Avatar asked Aug 30 '13 18:08

Rendy


People also ask

What is the purpose of dimens xml?

Reusing values - If you need to use the same dimension multiple places throughout your app (for example, Activity layout padding or a TextView textSize ), then using a single dimen value will make it much easier to adjust later. This is the same idea as using styles and themes.

What is Dimen in xml?

Note: A dimension is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine dimension resources with other simple resources in the one XML file, under one <resources> element.

What folder stores the dimens xml?

The res/values folder is used to store the values for the resources that are used in many Android projects to include features of color, styles, dimensions etc. Below explained are few basic files, contained in the res/values folder: colors. xml: The colors.


1 Answers

No. The resources are resolved as the per the device and its orientation. Hence you cannot use references to other resources and have calculations on them in dimens.xml.

like image 63
sriramramani Avatar answered Oct 13 '22 18:10

sriramramani