Q:

Android Why the Horizontal scroll does not fit the whole width

This a ListView screenshot of my problem:

This is the layout XML:

<LinearLayout 
    android:id="@+id/viewer_top"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/background_dark"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/viewer_filter"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableRight="@android:drawable/ic_menu_search"
        android:hint="@string/hint_filter"
        android:background="@android:color/white"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="3dp"
        android:inputType="text"
        android:paddingLeft="4dp"
        android:selectAllOnFocus="true" >
    </EditText>

    <EditText
        android:id="@+id/viewer_search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableRight="@android:drawable/ic_menu_search"
        android:hint="@string/hint_search"
        android:background="@android:color/white"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        android:layout_marginTop="3dp"
        android:layout_marginBottom="5dp"
        android:inputType="text"
        android:paddingLeft="4dp"
        android:selectAllOnFocus="true" >
    </EditText>
</LinearLayout>

<HorizontalScrollView
    android:id="@+id/viewer_hscroll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/viewer_top" >
    <ListView
        android:id="@+id/viewer_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </ListView>
</HorizontalScrollView>

There are 3 problems in this scenario:

The Horizontal scrollview does not cover the full screen width (I drew a thick red line to mark the end)
The Horizontal scrollview does not scroll horizontally
The ListView rows are not of uniform width (this can be seen by the background color ending) (see the getView code below for details)
private static final int listRowLayout = android.R.layout.activity_list_item;
private Map<String, Integer> mColors = new HashMap<String, Integer>();

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // No logs here to keep ListView performance good
    ViewHolder holder;
    int color;

    if( convertView == null ) {
        convertView = mInflater.inflate(listRowLayout, parent, false);
        holder = new ViewHolder();
        holder.text = (TextView) convertView.findViewById(android.R.id.text1);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    String data = mData.get(position);

    // A compiled regex is faster than String.Contains()
    Matcher m = ViewHolder.regex.matcher(data);
    if( m.find() ) {
        color = mColors.get(m.group(1));
    } else {
        color = mColors.get("V");
    }

    holder.text.setText(data);
    holder.text.setBackgroundColor(color);
    return convertView;
}

private static class ViewHolder {
    TextView text;
    static Pattern regex = Pattern.compile(" ([VIDWEF])/");
}

}

A:

This is the solution I found.
The root of all evil :-) is that ListView is not designed to efficiently deal with rows of different length. To determine the ListView width, instead of looking at all the rows, only 3 rows are taken as average.
So, if the 3 rows are by chance short rows, the width will be clipped for the longer rows, it explains the problems I experienced.
To bypass this I calculated the maximum row length for all data, and I padded shorter rows with spaces, it solved all 3 problems I described in the question.
The code for padding (executed inside getView() )
holder.text.setText(String.format("%1$-" + mLen + "s", data));

