2016-11-29 4 views
0

私は私の背景画像は、画面の上端から代わりのactionBarの下に延びるように、活動の内容の上にactionBar「フロート」を作るためにinstructions hereを次しています。しかし、match_parentlistViewを上端に揃えているので、listViewactionBarの下部に揃える必要があります。Android:listViewをカスタムアクションバーの下部に揃える方法は?

enter image description here

のみxmlでそれを実現する方法はありますか? actionBaridはどうすればlayout_belowに設定できますか?

listViewの上余白を設定するコードでactionBarの高さを取得/推定できると確信していますが、私はより洗練されたソリューションを望んでいます。おかげ

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

ちょうどあなたのリストビュー

android:layout_marginTop="?actionBarSize" 
+0

THXにlayout_marginTopを追加し、あなたのソリューション実際に働く – rockhammer

関連する問題