How to create a style for Imageview on Android?

Asked

Viewed 159 times

0

How to create a format style for ImageView passing to length and height in this style so it gets "formatted" on the screen?

  • Dude, I don’t quite understand your question. There’s a way to clarify?

  • Could define better screen formatted? You want it to respect the size of the screen?

  • @Thiagoluizdomacoski not this, imagine a rectangle I want to pass to this IamgeView which shall have this format as measures specified in style

  • This you want to do via code? Pass height and width in Java?

  • @Thiagoluizdomacoski may be, but I was thinking xml in the styles

1 answer

2


You can specify fixed file sizes dimens.xml which is in the folder res/values/.

For screens with more than 820dp (screens of 7" and 10") you include in the file dimens.xml inside the folder res/values-w820dp/

Example:

<ImageView
    android:layout_width="@dimen/image_view_w"
    android:layout_height="@dimen/image_view_h”
...  
>
</ImageView>

dimens.xml:

<dimen name="image_view_w">55dp</dimen>
<dimen name="image_view_h">55dp</dimen>
  • 1

    @Thiagoluizdomascoski I will test first, then and I mark as solved blz.

  • how to pass this command via code?

  • imageView.setLayoutParams(new LinearLayout.LayoutParams(R.dimen.image_view_w, R.dimen.image_view_h));

  • but it moves the image size and not imageView

Browser other questions tagged

You are not signed in. Login or sign up in order to post.