蔺飞飞 2019-08-09 16:31 采纳率: 100%
浏览 611
已采纳

安卓Dilog使用百分比约束布局,无法显示?

写一个dialog对话框,使用了百分比布局,代码如下

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">


    <android.support.constraint.ConstraintLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintWidth_percent="0.8"
        app:layout_constraintHeight_percent="0.6"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:background="@drawable/dial_show_code">
                ..............
                    </android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>

展示在dialog里,代码如下

AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View inflate = LayoutInflater.from(context).inflate(R.layout.dialog_show_code, null);
        builder.setView(inflate);
        AlertDialog simpleDialog = builder.create();
        simpleDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        simpleDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        simpleDialog.show();
        simpleDialog.setCancelable(true);

结果显示不出来!!!!!!!!!!!!!
使用固定宽高,可以显示!!!!!!!!!!!!!!
请问大家这是什么原因????????????????

  • 写回答

2条回答

  • lht80s 2019-08-29 17:24
    关注

    你这布局我试了,没问题,但我用的是androidx.constraintlayout.widget.ConstraintLayout
    而非你的android.support.constraint.ConstraintLayout。
    support的时代已经过去了,雄起吧少年,一起进入androidx的时代吧。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波