我跟隨instructions here使actionBar
「浮動」在活動內容的頂部,以便我的背景圖像從屏幕的上邊緣延伸而不是在actionBar
之下。不過,現在我需要將我的listView
與actionBar
的底部對齊,因爲match_parent
現在會將listView
對齊到頂部邊緣。Android:如何將listView對齊到自定義actionBar的底部?
有沒有辦法實現,在只xml
? actionBar
的id
是什麼因此我可以設置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>
XML插入THX – rockhammer