Android 是否存在隐式列表片段边距/填充?如何删除它?

Android 是否存在隐式列表片段边距/填充?如何删除它?,android,android-layout,Android,Android Layout,在我的布局中使用ListFragment时,我发现它有不需要的左边距-图像上的红色部分(上升到操作栏) 我还没有找到关于这个问题的任何文档,但希望有人知道-我如何删除这个空间 您可以从图像中看到,边距不在列表项级别上,但在更高的级别上-因此我猜它是片段边距 值得注意的是,其他片段都很好,并被拉伸到全屏宽度。唯一有问题的片段是那些扩展ListFragment的片段 我也遇到了同样的问题。我正在使用ActionBarSherlock,并且能够用修复此问题 首先,我将以下内容添加到我的themes.x

在我的布局中使用
ListFragment
时,我发现它有不需要的左边距-图像上的红色部分(上升到操作栏)

我还没有找到关于这个问题的任何文档,但希望有人知道-我如何删除这个空间

您可以从图像中看到,边距不在列表项级别上,但在更高的级别上-因此我猜它是片段边距

值得注意的是,其他片段都很好,并被拉伸到全屏宽度。唯一有问题的片段是那些扩展
ListFragment
的片段


我也遇到了同样的问题。我正在使用ActionBarSherlock,并且能够用修复此问题

首先,我将以下内容添加到我的themes.xml中:

<style name="Theme.Base" parent="@style/Theme.Sherlock.Light.DarkActionBar">
    ...
    <item name="android:listViewStyle">@style/ListViewStyle.MyApp</item>
    ...
</style>
您也可以尝试以下设置之一:

    <item name="android:layout_marginLeft">0dp</item>
    <item name="android:padding">0dp</item> <!-- Instead of paddingLeft, if you want 0, everywhere -->
0dp
0dp

将ListView指向我的自定义样式解决了我的问题。本质上,在ListView小部件上设置样式应该可以做到这一点。

您最好覆盖布局,因为填充是ListFragment默认布局的一部分

因此,布局类似于以下内容:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

<ListView
    android:id="@id/android:list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:visibility="gone"
    android:drawSelectorOnTop="false" />

<TextView
    android:id="@id/android:empty"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="No data" />
</LinearLayout>
有点冗长,但这是最灵活的方法

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

<ListView
    android:id="@id/android:list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:visibility="gone"
    android:drawSelectorOnTop="false" />

<TextView
    android:id="@id/android:empty"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="No data" />
</LinearLayout>
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_bet_statement_list, container, false);
...
}