Is an implicit list box / list populate? How to remove it?

When using ListFragment in my layout, and I found that it has an undesirable left margin - the red part in the image (which rises to the action bar.

I do not have documentation on this issue, but hopefully someone finds out - how can I remove this space?

It can be seen from the image that the margin is not at the level of the list item, but it is at some higher level, so I assume that this is the edge of the fragment.

It is noteworthy that other fragments are simply beautiful and stretched to the full width of the screen. The only problematic snippets are those that extend the ListFragment .

unwanted margin is in red

+4
source share
2 answers

I had the same problem. I am using ActionBarSherlock and was able to fix this with Styles and Themes .

First I added this to my .xml topics:

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

This tells SherlockListFragment use my own style for ListView . Then I added this style to my styles. Xml:

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

You can also try one of the following options:

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

Pointing ListView to my custom style fixed the issue for me. Essentially, setting styles in ListView widgets should do the trick.

0
source

You are best at overriding the layout, since padding is part of the default layout in the ListFragment.

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

therefore the layout is similar to the following: -

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

and then fill it in onCreateView ()

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

A bit detailed, but this is the most flexible way to do this.

0
source

All Articles