【发布时间】:2016-03-26 17:49:47
【问题描述】:
我正在尝试创建一个高度为 80dp 的片段,在设计部分它似乎工作得很好,但是当我在我的设备上运行应用程序时,RelativeLayout 不知何故需要全屏。我对 SeekBar 使用 android:layout_alignParentBottom="true",但据我所知,如果 Layout 的高度不是 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:我只是尝试将此布局用于活动,它不再需要全屏,但我仍然遇到片段问题。另外,我不会以编程方式更改 Layout 的高度。
编辑2:我使用fragmentTransaction.add(R.id.musicBarContainer, musicProgressBar) 将片段添加到活动中,其中musicProgressBar 是片段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);
【问题讨论】:
-
xml 就好了。您是否正在以编程方式更改某些内容,例如更改高度运行时间? @Joose
-
@Joose 看看我的回答。
-
怎么称呼你的片段和片段布局?
-
@Ozlem,请查看 EDIT 2
-
我把你的代码sn-ps写到一个空的项目中,我没有遇到你的问题,即出现fragment的情况下布局不是全屏。也许你错过了代码中的一点;你能写下你的整个代码,以便我们可以正确地检查它吗?
标签: android xml android-layout