2014-10-02 64 views
1

我有一个SlidingPaneLayout其中左窗格是一个ListView和右窗格是详细视图。 XML如下。如何设置宽度为100%的ListView部分SlidingPaneLayout

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

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> 

回答

1

在这种情况下,列表视图绑定到取固定值,因此改变列表视图的宽度参数,并把一些非常大的值在width属性等500dp或1000dp。

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


     android:layout_marginRight="0dp" /> 
+0

确定这工作,但我不知道是否需要在Java中添加任何特殊的代码来检测屏幕宽度和设置它高于这个值,或者像1000dp这样的大值会照顾它。谢谢,将标记为答案。 – user1406716 2014-10-02 07:54:31

+0

您可以在程序中找到屏幕宽度。但我怀疑这会反映在屏幕上,因为这个设置必须在视图创建之前提供给滑动面板,这就是为什么相对宽度值不能在这里工作。 – 2014-10-02 07:56:25

0

在XML属性下面使用了列表视图: 应用:layout_widthPercent =“100%”

相关问题