Relativelayout Is Taking Fullscreen for Wrap_Content

RelativeLayout is taking fullscreen for wrap_content

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.

Relativelayout not wrapping its content

remove android:layout_alignParentBottom="true" from both your EditText and ImageView will solve your proble.

Your RelativeLayout already have android:layout_alignParentBottom="true" and if you will set same for it's child also it will set layout height to full screen.

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 Document

Why does my relative layout occupy full screen width

The other answers have correctly pointed out that when your relative layout's width is set to wrap_content, and its children are aligned to both left and right, the relative layout takes the width of its parent - in this case, the entire screen. If, however, both children were aligned to one side, the relative layout would be as wide as the widest child.

Now if you want the two buttons to be placed next to each other, and the relative layout to be as wide as the sum of the widths of the buttons, a slightly different approach is needed. Instead of positioning both buttons relative to the parent, do that with one button only (e.g, the first one). Let's say its positioning is left unchanged (android:layout_alignParentRight="true"). Now the button is floated to the right, so the second button, in order to be position next to it, has to be aligned to the first button's left side. Thus, we just add android:layout_toLeftOf="@id/Button01" (and remove the android:layout_alignParentLeft="true" part).

For more, I suggest you check out a very friendly tutorial on relative layouts.

RelativeLayout takes fullscreen with layout_height=80dp

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);

Dialog Fragment with wrap_content coming as a full screen. How to make it as a height of layout and not a full screen?

Solved by changing RelativeLayout to LinearLayout and setting weight of list to 1
as follows

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical"
android:padding="5dip" >

<ListView
android:id="@+id/product_list"
android:background="@drawable/border_details"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<RelativeLayout
android:id="@+id/AddtoCart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="10dp"
android:background="#005959" >

<Button
android:id="@+id/button_addToCart"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
android:background="@drawable/gradient_button"
android:text="@string/add_to_cart"
android:textColor="#000000" />

</RelativeLayout>
</LinearLayout>


Related Topics



Leave a reply



Submit