【问题标题】:Why does wrap_content is filling height?为什么 wrap_content 填充高度?
【发布时间】:2014-11-06 16:13:34
【问题描述】:

我正在尝试使用 RelativeLayout 包装它的内容高度和宽度。它似乎在宽度上做得很好,但高度没有包裹。它覆盖了整个屏幕。有人知道为什么吗?

<?xml version="1.0" encoding="utf-8"?>



   <com.company.things.CameraControls
       xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/camera_control_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#60FFFFFF" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:onClick="clearDrawing"
            android:text="@string/clear" />

        <SeekBar
            android:id="@+id/sensitivity_seek"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true" />

        <Switch
            android:id="@+id/live_switch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/sensitivity_seek"
            android:layout_toRightOf="@+id/sensitivity_seek"
            android:text="@string/live" />

    </RelativeLayout>

</com.company.things.CameraControls>

【问题讨论】:

  • 可能是因为你把你的UI元素放在了底部
  • @TimCastelijns 这行得通。这很奇怪。我想将元素与相对布局和 wrap_content 的底部对齐。该按钮比其他元素大。我想我可以对准按钮。让它成为答案,我会接受。

标签: android android-layout android-xml android-wrap-content


【解决方案1】:

这是因为您将 UI 元素放在页面底部。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-26
    • 2019-11-12
    • 2017-02-25
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    • 2020-07-07
    相关资源
    最近更新 更多