TextViewをの上部と下部に固定することができますListView(必要な効果に応じて、オプションで左右にも固定できます)。これにより、TextView同じ高さ(およびオプションで幅広)になるため、中心重力を使用してテキストを中央に配置します。
<?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" >
<ListView
android:id="@+id/lvHaltestellen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/tvHaltestellen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/lvHaltestellen"
android:layout_alignBottom="@+id/lvHaltestellen"
android:layout_alignLeft="@+id/lvHaltestellen"
android:layout_alignRight="@+id/lvHaltestellen"
android:gravity="center" />
</RelativeLayout>
に背景色を追加する場合は、色がリストに表示されているものを覆い隠さないように、TextView別の透明なコンテナ(例:)でラップする必要があります。FrameLayout何かのようなもの:
<?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" >
<ListView
android:id="@+id/lvHaltestellen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/lvHaltestellen"
android:layout_alignLeft="@+id/lvHaltestellen"
android:layout_alignRight="@+id/lvHaltestellen"
android:layout_alignTop="@+id/lvHaltestellen" >
<TextView
android:id="@+id/tvHaltestellen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@android:color/black" />
</FrameLayout>
</RelativeLayout>
または、ListViewの高さ全体を塗りつぶす場合は、をリストRelativeLayoutに固定する必要はありません。TextView@ user1796624ですでに指摘されているように、次に中央に配置することができますTextView。
他の誰かの答えに対するあなたの以前のコメントによると:
テキストビューはリストビュー内に表示されます。
ここであなたが言おうとしていることは理解できますが、は内部に座っているのでTextViewはなくListView、その上に浮かんでいることを理解してください。