Martynas
Martynas

Reputation: 627

Dialog window is not wraping content

I have simple RelativeLayout with wrap_content width and height. But it does not wrap it. Maybe I miss something.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/Wheat">

    <LinearLayout
        android:id="@+id/btn_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:background="@android:color/black">

        <Button
            android:id="@+id/saveNewBtn"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="saveData"
            android:text="Save" />

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="cancelAction"
            android:text="Cancel" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:id="@+id/linearlayout"
        android:orientation="vertical">
    </LinearLayout>


</RelativeLayout>

Will update in a sec with a screen shot.

application screenshot

Upvotes: 0

Views: 40

Answers (1)

REG1
REG1

Reputation: 486

Try this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout     
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/Wheat">

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:id="@+id/linearlayout"
    android:orientation="vertical">
</LinearLayout>

<LinearLayout
    android:id="@+id/btn_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_below="@id/linearlayout"
    android:background="@android:color/black">
    <Button
        android:id="@+id/saveNewBtn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:onClick="saveData"
        android:text="Save" />

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:onClick="cancelAction"
        android:text="Cancel" />
</LinearLayout>

</RelativeLayout>

I removed the android:layout_alignParentBottom="true" from bin_layout and instead set: android: layout_below="@id/linearlayout

Upvotes: 1

Related Questions