I know that this kind of questions has already been asked elsewhere. But I don't understand why I have got a problem in the following specific case. Here is the very simple layout:
<RelativeLayout
android:id="@+id/headerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#D0D0D0"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/appImageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="@+id/appNameTextView"
android:layout_alignTop="@+id/appNameTextView"
android:scaleType="centerInside"
android:src="@drawable/common_ic_googleplayservices"
android:background="#FF0000"
/>
<TextView
android:id="@+id/appNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/appImageView"
android:text="Here is some text"
android:textColor="#000000"
/>
</RelativeLayout>
Here is the result:
common_ic_googleplayservices is a square image which is scaled down. Why do I have a padding (see the red area) => my image is no more square.
How to solve the problem ? (please test quickly before giving an answer :) )
Thanks !!!
What you are trying to do is not directly possible with
RelativeLayout
or any other default layouts, for this you needPercentRelativeLayout
. But I suggest not to include any additional dependencies for such Task.Step-1: Make your UI like following
Step-2: Make following changes in JAVA code.
Use this
Try this,