Java 在屏幕顶部下方启动ListView
我正在尝试在我的Java 在屏幕顶部下方启动ListView,java,android,xml,listview,Java,Android,Xml,Listview,我正在尝试在我的列表视图上方添加某种填充或边距,以便添加带有图像和按钮的自定义导航栏。我已经尝试在XML中添加了填充和边距,但我的ListView似乎仍然从顶部开始 如何启动列表视图,使其低于屏幕顶部大约50p 布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_w
列表视图
上方添加某种填充或边距,以便添加带有图像和按钮的自定义导航栏。我已经尝试在XML中添加了填充和边距,但我的ListView
似乎仍然从顶部开始
如何启动列表视图,使其低于屏幕顶部大约50p
布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mycompany.myapp.myActivity"
android:padding="0dp">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/theList"
android:paddingTop="44dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/imageView" />
</RelativeLayout>
填充
在应用它的容器的边界内添加空间。您可以在列表视图上使用marginTop
(margin
在应用它的容器的边界之外添加空间),也可以在相对视图上使用paddingTop
对于您的情况,您可能应该使用,并将其放置在列表视图的上方。例如,如果使用线性布局
而不是相对布局
,只需给出工具栏
维度,就会将列表视图推到其下方 试试这段代码。
第二个LinearLayout
可用于保存您选择的自定义导航项目,并让它选择其高度。
listview将自动填充视图的其余部分
类似于此的内容,请尝试为ListView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.mycompany.myapp.myActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Place your images and buttons need for navigation here -->
<!-- Also dont forget to choose the appropiate orientation to this layout-->
</LinearLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="fillparent"
android:id="@+id/theList"/>
</LinearLayout>
请添加您的布局xml添加您所拥有和想要的图片。我似乎找不到工具栏。它应该在widgets下吗?工具栏
是在API 21中添加的。您可以在以前的版本中使用它的SupportV7版本。您需要将compile'com.android.support:appcompat-v7:21.0.3'
添加到模块的build.gradle
我目前有这个compile'com.android.support:appcompat-v7:21.0.3'
请记住,当视图未包含在XML层次结构中时,将其添加到XML层次结构时,需要完全指定视图的整个包名SDK本身。在这种情况下,…
这个答案与我上面的答案没有任何不同。另外,您没有解释为什么使用margin
而不是padding
有效。在SO中,不鼓励只使用代码的答案。