最近开发老遇到莫名其妙的问题,dialog自定义大小,setAttributes这个方法没反应是肿么一回事

============问题描述============


最近开发老遇到莫名其妙的问题,dialog自定义大小,setAttributes这个方法没反应是肿么一回事,我只想让dialog显示一部分,但是居然全屏占满了,很费解,以前开发都是这样写的,现在居然不可以了
这是dialog的code
DownLoaderDialog dialog=new DownLoaderDialog(MainActivity.this,R.style.dialog);

				Window mwindow=dialog.getWindow();

				WindowManager.LayoutParams lp=mwindow.getAttributes();

				int[] location = new int[2];

				button.getLocationOnScreen(location);

				WindowManager m = getWindowManager();

				Display d = m.getDefaultDisplay();

				lp.y=location[1];

				lp.height = (int) (d.getHeight() * 0.6);

				mwindow.setAttributes(lp);

				dialog.show();

这是dialog的xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical" >



    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="0px"

        android:layout_weight="1"

        android:background="#ECEFF0" >



        <ListView

            android:id="@+id/listView1"

            android:layout_width="match_parent"

            android:layout_height="wrap_content" >

        </ListView>



    </LinearLayout>



    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="50dp"

        android:background="#0BA683"

        android:gravity="center_vertical"

        android:orientation="horizontal" >



        <Button

            android:id="@+id/btnDelete"

            android:layout_width="0px"

            android:layout_height="match_parent"

            android:layout_weight="1"

            android:background="@drawable/btn_pressed_style"

            android:text="删除"

            android:textColor="#FDFEFE"

            android:textSize="16sp" />



        <View

            android:layout_width="1dp"

            android:layout_height="match_parent"

            

            android:background="#DADBDA" />



        <Button

            android:id="@+id/btnSelectAll"

            android:layout_width="0px"

            android:layout_height="match_parent"

            android:layout_weight="1"

            android:background="@drawable/btn_pressed_style"

            android:text="全选"

            android:textColor="#FDFEFE"

            android:textSize="16sp" />

    </LinearLayout>



</LinearLayout>

============解决方案1============


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 改 wrap_content试试
    android:layout_height="fill_parent"
    android:orientation="vertical" >

============解决方案2============


好奇怪的写法。

============解决方案3============


问题应该在R.style.dialog里
posted @ 2014-11-12 10:22  android开发教程2015  阅读(261)  评论(0编辑  收藏  举报
我要啦免费统计