2

dialogfragmentそのため、単純な「ユーザーに選択してもらう」ポップアップを作成した後、それをロードすると、レイアウトに奇妙な余分な空白がいくつか見られました.何が原因なのかわからず、それを理解しようとして頭を悩ませていました. 動作をより適切に表示するために xml を少し変更しました。唯一の違いは、3 つの垂直セクションの幅を「match_parent」から「wrap_content」に変更したことです。これにより、ボーダーを使用して空白の実際のサイズを表示できます。 . 問題を示す図を次に示します。

問題

ここに私の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>

私の質問は次のとおりです。この余分な空白を削除するにはどうすればよいですか? 私のxmlレイアウトに何か欠けていますか? 幅のサイズは毎回手動で設定できますが、ウィンドウ自体を実際に「wrap_content」にしたいです。

編集:サイズ変更はタイトルが原因であることが判明しました。タイトルを適切なサイズに縮小する方法はありますか?

4

2 に答える 2

13

犯人はタイトルでした。設定:

getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 

私のダイアログフラグメントではoncreateview、すべてのサイズの問題が修正されました。新しいimageviewものを一番上に追加し、フォトショップで独自のタイトルをデザインしました。

于 2013-12-01T05:13:58.177 に答える
0

から へandroid:layout_widthの変更 。アウターに追加することもできますTextView"fill_parent"android:gravity="center"LinearLayout

于 2013-12-01T04:41:49.283 に答える