我正在尝试创建一个高度为 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
这正是您的情况。 relativeLayout 无法做到这一点。
有关更多详细信息,请访问此答案:RelativeLayout is taking fullscreen for wrap_content
关于android - relativelayout采用全屏,layout_height为="80dp",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36231873/