2

I'm trying to create a fragment with height of 80dp, and at Design section it seems to work pretty well, but when I run the app on my device, RelativeLayout somehow takes a fullscreen. I use android:layout_alignParentBottom="true" for the SeekBar, but as far as I know it shouldn't take fullscreen if Layout's height isn't wrap_content. Here is the XML code:

<?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>

EDIT 1: I just tried to use this layout for an activity and it doesn't take fullscreen anymore, but I still have a problem with fragment. Also, I don't change Layout's height programmatically.

EDIT 2: I use fragmentTransaction.add(R.id.musicBarContainer, musicProgressBar) to add the fragment to activity, where musicProgressBar is an instance of fragment java class. The musicBarContainer XML code is

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

In onCreateView I use View view = inflater.inflate(R.layout.music_progress_bar, null);

7
  • xml is just fine . are you changing something programmatically like change height run time? @Joose Mar 26, 2016 at 5:25
  • @Joose check out my answer.
    – user6011162
    Mar 26, 2016 at 5:37
  • How do you call your fragment and fragment layout?
    – ozo
    Mar 26, 2016 at 7:11
  • @Ozlem, please check out EDIT 2
    – ulmaxy
    Mar 26, 2016 at 7:20
  • I wrote your code snippets to an empty project, and I did not encounter your problem, i.e., the layout was not full screen in case of fragment. Maybe you miss a point in your code; could you write your whole code so that we can inspect it properly?
    – ozo
    Mar 26, 2016 at 8:30

3 Answers 3

2

From the RelativeLayout doc:

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

Which is exactly your case. RelativeLayout can not do that.

for more detail visit this answer : RelativeLayout is taking fullscreen for wrap_content

1
  • I guess it's not the case, because layout's height isn't relative here, it's strictly defined as 80dp. Am I wrong?
    – ulmaxy
    Mar 26, 2016 at 5:43
1

In MusicProgressBar fragment class, instead of

        View view = inflater.inflate(R.layout.music_progress_bar, null);        

you should write

        View view = inflater.inflate(R.layout.music_progress_bar, container, false);
0
0

Try setting the height of seekbar to 20dp and check. I think its wrap_content is overriding the parents height parameter somehow.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.