Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, as I see from the answers, there is no solution to force image views to change theirs width and height proportionally. So, this can be solved only programmatically. There is my solution below :</p> <p>a) Create you custom layout class </p> <p>(don't forget to override all the parent constructors with <b>public</b> access modifier, otherwise GUI editor will fail):</p> <pre><code>public class MyLayout extends RelativeLayout {... </code></pre> <p><del>b) Override method:</del> <b>Deprecated - changing layout params in this method might cause side effects. See recommended approach below</b></p> <p><code><del> protected void onLayout(boolean changed, int l, int t, int r, int b) { </del></code></p> <p><code><del> ImageView icon = (ImageView) findViewById(R.id.my_image);</del></code> <code><del> icon.setMaxWidth(icon.getMeasuredHeight());</del></code></p> <p><code><del> super.onLayout(changed, l, t, r, b);</del></code></p> <p><code><del> }</del></code></p> <p>b) Add creational method:</p> <pre><code>public static MyLayout createLayout(ViewGroup parent) { Context context = parent.getContext(); MyLayout item = (MyLayout) LayoutInflater.from(context).inflate( R.layout.my_layout, parent, false); TextView tv = (TextView) findViewById(R.id.title); ImageView icon = (ImageView) findViewById(R.id.my_image); ViewGroup.LayoutParams p = icon.getLayoutParams(); p.width = (int) tv.getTextSize();; icon.setLayoutParams(p); return item; } </code></pre> <p>c) Final layout:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;com.mypackage.MyLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"&gt; &lt;TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_toLeftOf="@+id/my_image" android:ellipsize="end" android:singleLine="true" android:text="Some text" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;ImageView android:id="@+id/my_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/title" android:layout_alignBottom="@+id/title" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:adjustViewBounds="true" android:src="@drawable/my_bitmap_image" /&gt; &lt;/com.mypackage.MyLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload