user1406716 user1406716 - 2 months ago 12
Android Question

How to set width to 100% for Listview part of SlidingPaneLayout

I have a SlidingPaneLayout in which left pane is a Listview and the right pane is the detail view. The XML is below.

Problem is that - how do i make the width of the listview to cover the entire screen? As you can see below (red arrows), the current width doesnt go all the way to the right of the screen.

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sliding_pane_layout"
android:layout_width="fill_parent"
android:layout_height="match_parent" >

<!--
The first child view becomes the left pane. When the combined
desired width (expressed using android:layout_width) would
not fit on-screen at once, the right pane is permitted to
overlap the left.
-->

<LinearLayout
android:id="@+id/ll_left_pane"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginRight="0dp" >

<ListView
android:id="@+id/left_pane"
android:layout_width="fill_parent"
android:layout_height="match_parent"


android:layout_marginRight="0dp" />
</LinearLayout>

<!--
The second child becomes the right (content) pane. In this
example, android:layout_weight is used to express that this
pane should grow to consume leftover available space when the
window is wide enough. This allows the content pane to
responsively grow in width on larger screens while still
requiring at least the minimum width expressed by
android:layout_width.
-->


<!-- Framelayout to display Fragments -->

<FrameLayout
android:id="@+id/frame_container_slidingpanedetailview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp" />

</android.support.v4.widget.SlidingPaneLayout>

Answer

The list view in this case is bound to take fixed value hence change the width parameter of list view and put some very big value in width attribute like 500dp or 1000dp.

<ListView
        android:id="@+id/left_pane"
        android:layout_width="500dp"
        android:layout_height="match_parent"


        android:layout_marginRight="0dp" />