1

我有一个SlidingPaneLayout,其中左窗格是 Listview,右窗格是详细视图。XML 如下。

问题是 - 我如何使列表视图的宽度覆盖整个屏幕?正如您在下面看到的(红色箭头),当前宽度不会一直到屏幕右侧。

在此处输入图像描述

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

3 回答 3

1

在这种情况下,列表视图必然采用固定值,因此更改列表视图的宽度参数并在宽度属性中放置一些非常大的值,例如 500dp 或 1000dp。

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


        android:layout_marginRight="0dp" />
于 2014-10-02T07:50:52.860 回答
0

我陷入了同样的问题,然后经过大量搜索,我得到了以下解决方案。尝试这个:

android:layout_width="wrap_content"
android:layout_height="wrap_content"

希望这可以帮助。

于 2018-06-01T15:02:33.063 回答
0

在 xml 中为 listview 使用以下属性:

app:layout_widthPercent="100%"
于 2016-09-23T20:37:45.027 回答