简体   繁体   中英

Android Fragment: empty space on top

I built an app with fragments and I have a ListView with a search widget on top. This Listview layout is the layout for one fragment. Whenever I start the app there is an annoying white part on top of the SearchWidget that makes the whole Layout look weird and I can't seem to get rid of it. It is below the title. But Maybe I am doing something wrong, maybe this has something to do with the action bar? I am new to fragments and have never used action bar. Maybe I am also using it wrong. Is there a possibility to get rid of it, or should I do something differently? http://imgur.com/rzcLztY (image of the Layout - the white space is what i want to get rid of)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal" >

<fragment
    android:id="@+id/listFragment"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_marginTop="?android:attr/actionBarSize"
    android:layout_weight="1.12"
    class="org.blabla.ListFragment"
    tools:layout="@layout/activity_people_list" >
</fragment>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
tools:context=".PeopleListActivity" >

<SearchView
    android:id="@+id/searchView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical" />

<ListView
    android:id="@+id/listView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     >

</ListView>

</LinearLayout>

Just figured it out myself:

android:layout_marginTop="?android:attr/actionBarSize"

consumed the space.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM