蔺飞飞 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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog