17

フラグメントを使用すると、レイアウトが上部の追加スペースによって妨げられ、これがどこから来ているのかわかりません。次のようになります。

ここに画像の説明を入力

この空きスペースの原因として考えられるものは何ですか? まだ見つけていないテーマやスタイル設定、またはこのスペースはアクションバー用に予約されていますか? 私は本当にこれを取り除きたいです。

対応するレイアウト xml と、ダイアログをインスタンス化するコードを次に示します。

XML:

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

        <ProgressBar
        android:layout_margin="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/search_progress"
        style="?android:attr/progressBarStyle"
        android:indeterminate="true" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/search_progress"
            android:text="Searching for:" />

        <TextView
            android:id="@+id/searchingNameTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:layout_alignBottom="@+id/search_progress"
            android:layout_alignLeft="@+id/textView1"
            android:text="Barcelona" />

</RelativeLayout>

ジャワ:

FragmentManager fm = this.getSupportFragmentManager();
mSearchingDialog = new SearchingDialogFragment();
Bundle bundle = new Bundle();
bundle.putString("name", mCityToAdd.userName());
mSearchingDialog.setArguments(bundle);
mSearchingDialog.show(fm, TAG);

スクロールビューに関連する問題だと思って、ここでもこの質問をしましたが、すべてのフラグメントにスペースが表示されます。

ScrollView は上部に余分なスペースを追加します

4

3 に答える 3

25

ダイアログのinまたはメソッドのgetWindow().requestFeature(Window.FEATURE_NO_TITLE);直前に呼び出すようにしてください。 setContentView(R.layout.<dialog_layout>);onCreate()onCreateView()

于 2013-08-27T12:31:17.083 に答える
22

の上部にある空きスペースを再利用/削除するには、2 つの方法がありますDialogFragment

簡単に削除したい場合:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); //  <--
    View view = inflater.inflate(R.layout.fragment_dialog, container, false);
    return view;
}

ダイアログのタイトルに再利用したい場合:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
     getDialog().setTitle("Some title..."); //  <--
     View view = inflater.inflate(R.layout.fragment_dialog, container, false);
     return view;
}
于 2014-03-05T11:32:17.763 に答える
5

さらに別の解決策:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(STYLE_NO_TITLE, getActivity().getApplicationInfo().theme);
    }

この例では、アプリケーションのデフォルト テーマを使用します。効果があるのではなく、setStyle()呼び出す必要があることにも注意してください。onCreate()onCreateView()

于 2014-04-28T08:39:13.500 に答える