AlertDialog内部自定义View宽高问题

发现AlertDialog内部自定义View宽高有问题时,我的布局layout如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/view_dialog"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/left"
        android:layout_weight="1"
        android:layout_gravity="center"/>
    <com.example.mytstapplication.MyView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="2"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/right"
        android:layout_weight="1"
        android:layout_gravity="center"/>
</LinearLayout>

此时,布局显示如下,嘻嘻,这完全没毛病,这就是我想要的布局,于是我运行程序
在这里插入图片描述
得到了如下布局,不嘻嘻

在这里插入图片描述
造成这个问题的原因是,AlertDialog的内部根布局宽高默认是wrap_content
也就是说我的l布局layout其实是这样的
在这里插入图片描述
修改了以后布局果然和我手机上显示的一样
在这里插入图片描述
然后把高度不对的那个组件高度设置为wrap_content就可以了
android:layout_height=“wrap_content”
在这里插入图片描述

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值