Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8689341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:37:23+00:00 2026-06-12T23:37:23+00:00

I have such layout: <?xml version=1.0 encoding=utf-8?> <RelativeLayout 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> <TextView

  • 0

I have such layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">

<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" />

<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" />

This layout does almost what I need: it makes image view height the same as text view. The image graphic contents stretched also keeping aspect ratio.

But, the width of the image view does not change! As a result, I have a wide gap between text and the image view! As a temporal solution, I override View#onLayout.

The question: how to change image width in xml layout?

UPDATE:

This is a final layout I need (text + a few images).
Look at the first image: its width should be exactly the same as scaled image in it with no paddings and margins:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:37:24+00:00Added an answer on June 12, 2026 at 11:37 pm

    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 :

    a) Create you custom layout class

    (don’t forget to override all the parent constructors with public access modifier, otherwise GUI editor will fail):

    public class MyLayout extends RelativeLayout {...
    

    b) Override method: Deprecated – changing layout params in this method might cause side effects. See recommended approach below

    protected void onLayout(boolean changed, int l, int t, int r, int b) {

    ImageView icon = (ImageView) findViewById(R.id.my_image);
    icon.setMaxWidth(icon.getMeasuredHeight());

    super.onLayout(changed, l, t, r, b);

    }

    b) Add creational method:

    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;
    }
    

    c) Final layout:

    <?xml version="1.0" encoding="utf-8"?>
    <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">
    
    <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" />
    
    <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" />
    </com.mypackage.MyLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such layout: frame_layout.xml <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/items android:layout_width=match_parent android:layout_height=match_parent> </FrameLayout>
I have such a activity with my list: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
I have the following application.xml <?xml version=1.0 encoding=utf-8?> <manifest xmlns:android=http://schemas.android.com/apk/res/android package=com.currency.mobile.android> <uses-permission android:name=android.permission.INTERNET/> <application
<?xml version=1.0 encoding=UTF-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/relativeLayout1 android:layout_width=fill_parent android:layout_height=wrap_content android:background=@drawable/background > <TabHost android:id=@android:id/tabhost android:layout_width=match_parent android:layout_height=fill_parent
I have started to work android application, I designed the layout in such RelativeLayout
Just recently, my Android XML files which define my layout and etc have stopped
so I have my main layout as such: <div class=menu> <?php include('/menu.php'); ?> </div>
i have four imageviews in a linear layout in such a manner that only
I have such XML structure which was returned by SharePoint web services. <rs:data ItemCount=4
I have recently started Android development on API version 16 (4.1). According to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.