AlertDialogのサイズ変更

1,296 views
Skip to first unread message

高橋士郎

unread,
Oct 19, 2014, 12:13:45 PM10/19/14
to android-g...@googlegroups.com
お世話になっています。
久しぶりに投稿させていただきます。

現在、Listviewをクリックした際に、AlertDialogを表示するよう考えています。
その際に、itemに応じたimageを表示しているのですが、
AlertDialogがimageのサイズに依存してしまい、困っています。
CENTER_CROPを使っているので、横幅は合うのですが、
縦幅が拡大前のサイズに縛られてしまいます。
そこで、AlertDialogの高さを画面サイズで固定するよう、以下のとおり作成しました。
しかし、全く結果が変わらず、困っています。
どなたか、わかる方教えていただけないでしょうか?

Display disp = getWindowManager().getDefaultDisplay();
dispWidth = disp.getWidth();
dispHeight = disp.getHeight();

LayoutInflater inflater 
   = LayoutInflater.from(MainActivity.this);
view1 = inflater.inflate(R.layout.image, null);

ImageView imageView = (ImageView) view1.findViewById(R.id.imageView1);
        
imageView.setImageBitmap(image0);
imageView.setScaleType(ScaleType.CENTER_CROP);


Builder builder = new AlertDialog.Builder(MainActivity.this)
.setTitle(map.get("src").toString())
.setIcon(null)
.setView(view1)
.setPositiveButton(
"Ok", 
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
     
     
}
     
})
.setNegativeButton(
"Close", 
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
     
}
});
         
AlertDialog dialog_play = builder.create();
WindowManager.LayoutParams wmlp=dialog_play.getWindow().getAttributes();

wmlp.width=(int) Math.round(dispWidth*0.8);
wmlp.height=(int) Math.round(dispHeight*0.8);
wmlp.gravity=Gravity.CENTER;
dialog_play.getWindow().setAttributes(wmlp);
dialog_play.show();


レイアウト
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:gravity="left"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textSize="20dp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textSize="20dp" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/blank1" />

    <LinearLayout
        android:id="@+id/main_audio_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    </LinearLayout>

</LinearLayout>

Reply all
Reply to author
Forward
0 new messages