2012-10-17 50 views
3

我使用ActionBarSherlock創建DialogFragment。我將圖片的ID傳遞給DialogFragment。它僅包含的ImageView的:從DialogFragment如何使對話框適合圖像?

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

代碼:

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

但每次我得到這個:

dialog doesn't fit to image

對話框不適合於圖像。我使用AlertDialog(也是相同的SO post)獲得相同的行爲。

當試圖將圖像設置爲背景(setBackgroundResource)時,圖像適合對話框(圖像填充屏幕截圖上顯示的未使用空間)。

如何避免這種情況並使對話框適合圖像?有什麼解決方法嗎?

請幫忙。

回答

1

經過漫長的搜索和很多不成功的嘗試來解決這個問題,我找到了一個解決方案。

我需要設置android:adjustViewBounds="true"