Android:ListView 有奇怪的边距

标签 android android-layout listview

我正在尝试制作一个带有操作栏、 float 按钮和 ListView 的应用。

当我在 Android Studio 中添加 ListView 时,它的所有边总是有很大的边距。

无论我在布局代码中更改什么都无济于事,它总是看起来像这样: enter image description here

我的布局代码如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="appenzeller.de.glimpse.MainActivity">

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/mainList" />

    <LinearLayout
        android:id="@+id/ly_bar_bottom"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="right"
        android:orientation="horizontal">
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/button_addc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="28dp"
            android:src="@drawable/ic_add_white_18dp"
            android:onClick="addNewEntry"
            app:borderWidth="0dp"
            app:elevation="6dp"
            app:pressedTranslationZ="12dp" />
    </LinearLayout>

</RelativeLayout>

我做错了什么?

最佳答案

尝试删除

android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"

来自你的 RelativeLayout。你说“四面八方”,我只能看到左/右。但如果是所有方面,您还必须删除“paddingTop”和“paddingBottom”。

关于Android:ListView 有奇怪的边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37472758/

相关文章:

android - 为 ListView 设置长按监听器

android - 一个按钮的多个 OnClickListener

android - 动态添加ImageView到LinearLayout出错

android - ViewAnimator 使用旋转动画在 View 之间转换

android - 抽屉布局在没有导航 Controller 的情况下不起作用

android - ScrollView 与 ListView 性能对比

c# - 为什么 ListView 拒绝显示其列、项目和子项目(仅显示组)?

java - 在多个 Activity 中使用 AsyncTask

Android:在不启动 Intent 的情况下使用街景

android - jQuery 手机 : page transitions cannot be set to none on Android