Android-清单视图顶部的空白空间
问题描述:
我目前有一个tabview
,里面有listview
。我在listview
中只有三个项目,由于某种原因,顶部有一堆空白区域。也就是说,第一项不是从顶部开始,而是从中间开始。有任何想法吗?此外,我想我正在使用错误的布局。如果我只需要显示三个项目,比listview
更好?谢谢。Android-清单视图顶部的空白空间
代码:
// Data to put in the ListAdapter
private String[] sdrPlaylistNames = new String[]{ "More Playlists...","Dubstep", "House"};
Intent playbackServiceIntentDUB, playbackServiceIntentHOUSE;
//alert dialog
AlertDialog.Builder builder;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playlists_layout);
//fill the screen with the list adapter
playlistFillData();
playbackServiceIntentDUB = new Intent(this, DUBAudioService.class);
playbackServiceIntentHOUSE = new Intent(this, HOUSEAudioService.class);
}
public void playlistFillData() {
//create and set up the Array adapter for the list view
ArrayAdapter<?> sdrListAdapter = new ArrayAdapter<Object>(this, R.layout.list_item, sdrPlaylistNames);
setListAdapter(sdrListAdapter);
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ListView
android:id="@id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/selectP" android:stackFromBottom="false">
</ListView>
<TextView
android:id="@id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp" />
<TextView
android:id="@+id/selectP"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:text="Select A Playlist Above"
android:textColor="#FF3300"
android:textSize="22dp"
android:textStyle="bold" >
</TextView>
</RelativeLayout>
答
哦,我错过了你在我以前的答案真正的问题。
只需设置android:layout_alignParentTop="true"
到您的列表视图
<ListView
android:id="@id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="@+id/selectP" android:stackFromBottom="false">
</ListView>
希望这一次我很清楚..
答
设置你的列表视图AlignParentTop = true
尽量使相对布局宽度和高度fill_parent并添加requestWindowFeature(Window.FEATURE_NO_TITLE);在你的onCreate()方法中。 –