android - relativelayout采用全屏,layout_height为="80dp"

标签 android xml android-layout

我正在尝试创建一个高度为 80dp 的 fragment ,在设计部分它似乎工作得很好,但是当我在我的设备上运行该应用程序时,RelativeLayout 不知何故采用全屏。我对 SeekBar 使用 android:layout_alignParentBottom="true" ,但据我所知,如果布局的高度不是 wrap_content ,它不应该全屏显示。 XML 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="80dp"
    android:background="#bbbbff">

    <SeekBar
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar"
        android:layout_alignParentBottom="true"
        android:layout_toLeftOf="@+id/playButton"/>

    <Button
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:text="play"
        android:layout_alignParentRight="true"
        android:id="@+id/playButton"/>
</RelativeLayout>

编辑1:我只是尝试将此布局用于 Activity ,它不再需要全屏,但我仍然遇到 fragment 问题。另外,我不会以编程方式更改布局的高度。

编辑2:我使用fragmentTransaction.add(R.id.musicBarContainer, musicProgressBar)将 fragment 添加到 Activity 中,其中musicProgressBar是 fragment java类的实例。 musicBarContainer XML 代码是

<FrameLayout
        android:id="@+id/musicBarContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
    </FrameLayout>

在onCreateView中我使用View view = inflater.inflate(R.layout.music_progress_bar, null);

最佳答案

来自 RelativeLayout 文档:

Class Overview

A Layout where the positions of the children can be described in relation to each other or to the parent.

Note that you cannot have a circular dependency between the size of the RelativeLayout and the position of its children. For example, you cannot have a RelativeLayout whose height is set to WRAP_CONTENT and a child set to ALIGN_PARENT_BOTTOM

Class documentation

这正是您的情况。 relativeLayout 无法做到这一点。

有关更多详细信息,请访问此答案:RelativeLayout is taking fullscreen for wrap_content

关于android - relativelayout采用全屏,layout_height为="80dp",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36231873/

相关文章:

android - Android Andengine场景添加背景

Android 模拟器 vs 手机 opengl 不一致

android - 非 Activity 类中的 findViewById

python - Python 中的 XML <arg> 值替换

java - 尽管设置了属性,但 Fragment GridView 第一项并未显示

android - 使用嵌套选择 Android SQLite 的复杂更新查询

java - 如何在 java 中将 org.w3c.dom.Element 输出为字符串格式?

android - 自己定义的 Layout , onDraw() 方法没有被调用

android - ListView:动态更改 sibling 的数据

android - RelativeLayout 中的 ImageView 具有顶部和底部填充