2016-11-29 67 views
0

我跟隨instructions here使actionBar「浮動」在活動內容的頂部,以便我的背景圖像從屏幕的上邊緣延伸而不是在actionBar之下。不過,現在我需要將我的listViewactionBar的底部對齊,因爲match_parent現在會將listView對齊到頂部邊緣。Android:如何將listView對齊到自定義actionBar的底部?

enter image description here

有沒有辦法實現,在只xmlactionBarid是什麼因此我可以設置layout_below

我敢肯定,我可以得到/估計代碼中的actionBar的高度,以相應地設置listView的頂部邊距,但我希望有一個更優雅的解決方案。由於

listView活動的xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_users" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:srcCompat="@drawable/img_people_512" 
     android:id="@+id/usersImageView" 
     android:alpha="0.55" 
     android:contentDescription="@string/backgroundImage" 
     android:scaleType="centerCrop" /> 

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/userListView" 
     /> 
</RelativeLayout> 

定製actionBar佈局XML

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/mainActionBar" 
    android:gravity="center"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:id="@+id/mainActionBarSpacer" 
     android:text="@string/mainActionBarSpacer" 
     android:textColor="@color/colourTransparent" 
     android:textSize="35sp" 
     android:fontFamily="cursive" 
     android:onClick="onClick" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_toRightOf="@+id/mainActionBarSpacer" 
     android:layout_toEndOf="@+id/mainActionBarSpacer" 
     android:gravity="center" 
     android:id="@+id/mainActionBarTitle" 
     android:text="@string/app_name" 
     android:textColor="@color/colourActionBarText" 
     android:textSize="35sp" 
     android:fontFamily="cursive" 
     android:onClick="onClick" /> 

</RelativeLayout> 
+0

XML插入THX – rockhammer

回答

0

只需添加layout_marginTop到您的列表視圖

android:layout_marginTop="?actionBarSize" 
+0

THX,您的解決方案實際上有效 – rockhammer