Skip to main content
Add explanations on how to place the styles and dims
Source Link
Iulian Popescu
  • 2.6k
  • 4
  • 25
  • 31

You can't do that in that way, but you have 2 options here:

Option 1: declare the value as a dimension and the use it:

Declare two values for height and width in dimens.xml that can be found at res/values.

<dimen name="image_width">100dp</dimen> <dimen name="image_height">100dp</dimen>   

Then use them in your xml like this:

<ImageView android:id="@+id/myimage2" android:layout_height="@dimen/image_height" android:layout_width="@dimen/image_width"/> 

Option 2: Create a style associated with your ImageView:

First thing to do is to create the style for your views and place it in styles.xml that can be found at res/values.

<style name="my_image_view_style"> <item name="android:layout_height">100dp</item> <item name="android:layout_width">100dp</item> </style>   

Add your created style to your ImageView:

<ImageView android:id="@+id/myimage2" style="@style/my_image_view_style"/> 

You can't do that in that way, but you have 2 options here:

Option 1: declare the value as a dimension and the use it:

<dimen name="image_width">100dp</dimen> <dimen name="image_height">100dp</dimen>   <ImageView android:id="@+id/myimage2" android:layout_height="@dimen/image_height" android:layout_width="@dimen/image_width"/> 

Option 2 Create a style associated with your ImageView:

<style name="my_image_view_style"> <item name="android:layout_height">100dp</item> <item name="android:layout_width">100dp</item> </style>   <ImageView android:id="@+id/myimage2" style="@style/my_image_view_style"/> 

You can't do that in that way, but you have 2 options here:

Option 1: declare the value as a dimension and the use it:

Declare two values for height and width in dimens.xml that can be found at res/values.

<dimen name="image_width">100dp</dimen> <dimen name="image_height">100dp</dimen> 

Then use them in your xml like this:

<ImageView android:id="@+id/myimage2" android:layout_height="@dimen/image_height" android:layout_width="@dimen/image_width"/> 

Option 2: Create a style associated with your ImageView:

First thing to do is to create the style for your views and place it in styles.xml that can be found at res/values.

<style name="my_image_view_style"> <item name="android:layout_height">100dp</item> <item name="android:layout_width">100dp</item> </style> 

Add your created style to your ImageView:

<ImageView android:id="@+id/myimage2" style="@style/my_image_view_style"/> 
Source Link
Iulian Popescu
  • 2.6k
  • 4
  • 25
  • 31

You can't do that in that way, but you have 2 options here:

Option 1: declare the value as a dimension and the use it:

<dimen name="image_width">100dp</dimen> <dimen name="image_height">100dp</dimen> <ImageView android:id="@+id/myimage2" android:layout_height="@dimen/image_height" android:layout_width="@dimen/image_width"/> 

Option 2 Create a style associated with your ImageView:

<style name="my_image_view_style"> <item name="android:layout_height">100dp</item> <item name="android:layout_width">100dp</item> </style> <ImageView android:id="@+id/myimage2" style="@style/my_image_view_style"/>