Reputation: 5796
I have the following XML code:
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:id="@+id/imgOffer"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="fitXY"
app:srcCompat="@drawable/applogo1" />
</TableRow>
</TableLayout>
According to this code, imgOffer
should get the entire width of it's parent tablerow
But the image width is not changing ( see images below )
It works fine when I hard-code the width (say 150dp)
What am I doing wrong here ??
Upvotes: 0
Views: 88
Reputation: 4132
use android:src="@drawable/applogo1" instead of app:srcCompat="@drawable/applogo1"
<ImageView
android:id="@+id/imgOffer"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="fitXY"
android:src="@drawable/applogo1" />
Edit: Use weight for imageview instead of giving match parent and try once
<ImageView
android:id="@+id/imgOffer"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="200dp"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_launcher" />
Upvotes: 1
Reputation: 8280
Looks like a bug, but it seems to work if you use weight 1 and width 0dp.
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:id="@+id/imgOffer"
android:layout_weight="1" <<<<<
android:layout_width="0dp" <<<<<
android:layout_height="200dp"
android:scaleType="fitXY"
app:srcCompat="@drawable/applogo1" />
</TableRow>
Upvotes: 1
Reputation: 116
this seems to solve it, use weight instead of width:
<ImageView
android:id="@+id/imgOffer"
android:layout_weight="1"
android:layout_height="200dp"
android:scaleType="fitXY"
app:srcCompat="@drawable/applogo1" />
source TableLayout with layout_width=matchparent not matching parent
Upvotes: 1