2012-11-27 122 views
4

在使用中我的佈局ListFragment,我發現它有不必要的左邊空白處 - 在圖像上的紅色部分(其上升到操作欄是否存在隱式ListFragment邊距/填充?如何刪除它?

我還沒有找到任何關於此問題的文件,但希望有人會知道 - 我如何刪除這個空間

您可以從圖像中看到,保證金不就行了項目的水平,但在某些更高級別的? - 所以我想這是片段保證金

值得注意的是,其他片段都很好,並延伸到全屏寬度。唯一有問題的片段是延伸ListFragment的片段。

unwanted margin is in red

回答

0

我有同樣的問題。我正在使用ActionBarSherlock,並能夠使用Styles and Themes修復此問題。

首先,我已將此添加到我的themes.xml:

<style name="Theme.Base" parent="@style/Theme.Sherlock.Light.DarkActionBar"> 
    ... 
    <item name="android:listViewStyle">@style/ListViewStyle.MyApp</item> 
    ... 
</style> 

這告訴SherlockListFragment使用個性化的風格爲它ListView。然後我說這個自定義樣式到我的styles.xml:

<style name="ListViewStyle.MyApp" parent="android:Widget.ListView"> 
    ... 
    <item name="android:paddingLeft">0dp</item> 
    ... 
</style> 

您也可以嘗試以下設置之一:

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

指向的ListView我解決了問題,我自定義樣式。從本質上講,在ListView Widget上設置樣式應該能夠做到。

0

您最好覆蓋佈局,因爲填充是ListFragment默認佈局的一部分。

http://developer.android.com/reference/android/app/ListFragment.html

所以類似下面的佈局: -

<?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> 

,然後填充它在onCreateView()

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    final View view = inflater.inflate(R.layout.fragment_bet_statement_list, container, false); 
... 
} 

有點冗長,但也是最靈活的方式去做這個。