Reputation: 4183
I'm creating DialogFragment
using ActionBarSherlock
. I'm passing an id of the image to DialogFragment
. It contains only of ImageView:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal" />
Code from DialogFragment:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dialog, container, false);
View iv = v.findViewById(R.id.imageF);
((ImageView) iv).setImageResource(imgId);
return v;
}
But every time I get this:
Dialog doesn't fit to image. I get the same behavior using AlertDialog
(also same SO post).
When trying to set image to background (setBackgroundResource
) the image fits to dialog (image fills the unused space which is shown on the screenshot).
How to avoid this and fit dialog to image? Is there any workaround?
Help, please.
Upvotes: 3
Views: 887
Reputation: 4183
After a long search and many unsuccessful attempts to solve this problem, I found a solution.
I needed to set android:adjustViewBounds="true"
.
Upvotes: 1