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" />
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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With