android - FrameLayout 中的嵌套 LinearLayout 与父级不匹配
问题描述
我有以下布局,在 FrameLayout 类中膨胀:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img"
android:layout_gravity="bottom|start"/>
<LinearLayout
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:text="Button"/>
</LinearLayout>
嵌套的 LinearLayout 与指定的父级不匹配,但将其内容包装为按钮的大小,我还尝试将匹配父级设置为 FrameLayout 的高度,
这里有什么问题?
解决方案
对 FrameLayout 使用 match_parent
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img"
android:layout_gravity="bottom|start"/>
<LinearLayout
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:text="Button"/>
</LinearLayout>
推荐阅读
- node.js - 如何在 Bigcommerce 结帐页面中创建文件上传表单并将其链接到订单 ID?
- python - 在 VS Code 中调试 Python 时如何自定义对象的字符串表示
- angular - 为什么 ngfor 绘制行而不绘制其中的数据
- unity3d - Unity 粒子未删除但在完成后发射
- javascript - 在 c# 中的 webbrowser 控件中访问 javascript 中的内容
- flutter - Flutter sendMessage()中的Firebase消息传递
- python - 如何使用 Python 从 Instagram 的 Post URL 中删除“?utm_source= something”
- javascript - 我想要实现的是过滤所有订单以获取每个卖家出售的所有产品
- for-loop - Robot Framework,如何从 Range 中获取奇数行表的值
- pine-script - 如何将指标转化为策略?