[英]Android: how to align listView to bottom of custom actionBar?
I am following instructions here to make the actionBar
"float" on top of an activity's contents so that my background image extends from top edge of screen instead of under the actionBar
. 我在这里按照说明将actionBar
“浮动”在活动内容的顶部,以便我的背景图像从屏幕的顶部边缘而不是在actionBar
下方延伸。 However, now I need to align my listView
to the bottom of the actionBar
because match_parent
now aligns the listView
to the top edge. 不过,现在我需要我的对齐listView
的底部actionBar
,因为match_parent
现在对齐listView
顶边。
Is there a way to achieve that in xml
only? 有没有一种方法只能在xml
实现? What would the id
of the actionBar
be so I can set layout_below
? 什么会的id
的的actionBar
是这样我就可以设置layout_below
?
I'm sure I can get/estimate the height of the actionBar
in code to set the top margin of the listView
accordingly but I'm hoping for a more elegant solution. 我确定我可以在代码中获取/估计actionBar
的高度,从而相应地设置listView
的上边距,但是我希望有一个更优雅的解决方案。 Thanks 谢谢
The listView
activity xml: 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>
the custom actionBar
layout xml 自定义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>
只需将layout_marginTop添加到您的列表视图
android:layout_marginTop="?actionBarSize"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.