Reputation: 482
So after making a dialogfragment
for a simple "have user choose" popup, I loaded it up and saw some odd extra whitespace in the layout, I'm unsure what's causing it and I've been wracking my brain trying to figure it out. I've modified the xml slightly to better show the behavior, the only difference is I've changed the widths of the 3 vertical sections from "match_parent" to "wrap_content" so I can use a border to show the actual size of the whitespace. Here is a picture showing the problem:
Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/pictureSourceMainTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/tvborder"
android:gravity="center"
android:text="Where would you like to choose\nyour image from?"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:id="@+id/pictureSourceIVLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/tvborder"
android:weightSum="3" >
<ImageView
android:id="@+id/pictureSourceCancelIV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/pictureSourceGalleryIV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/pictureSourceCameraIV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:id="@+id/pictureSourceTVLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="@+id/pictureSourceCancelTV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/tvborder"
android:gravity="center"
android:text="Cancel" />
<TextView
android:id="@+id/pictureSourceGalleryTV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/tvborder"
android:gravity="center"
android:text="Gallery" />
<TextView
android:id="@+id/pictureSourceCameraTV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/tvborder"
android:gravity="center"
android:text="Camera" />
</LinearLayout>
</LinearLayout>
So my question is: What can I do to remove this extra whitespace? Is my xml layout missing something? I could manually set the size of the width every time but I'd much rather the window itself actually "wrap_content"
EDIT: It turns out the resizing is being caused by the title, is there a way to shrink the title down to the proper size?
Upvotes: 2
Views: 2384
Reputation: 857
Change android:layout_width
of TextView
to "fill_parent"
.
You can also add android:gravity="center"
to the outer LinearLayout
Upvotes: 0
Reputation: 482
The culprit was the title. Setting:
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
in the oncreateview
in my dialogfragment fixed all size issues, I simply added a new imageview
to the top and designed my own title in photoshop.
Upvotes: 13