【问题标题】:How to set width to 100% for Listview part of SlidingPaneLayout如何将 SlidingPaneLayout 的 Listview 部分的宽度设置为 100%
【发布时间】:2014-10-02 07:34:51
【问题描述】:

我有一个SlidingPaneLayout,其中左窗格是列表视图,右窗格是详细视图。 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>

【问题讨论】:

    标签: android xml layout android-listview slidingpanelayout


    【解决方案1】:

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

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

    【讨论】:

    • 好的,但我想知道我是否需要在 java 中添加任何特殊代码来检测屏幕宽度并将其设置在该宽度之上,或者像 1000dp 这样的大值是否会处理它。谢谢,将标记为答案。
    • 您可以通过编程方式找到屏幕宽度。但我怀疑这会反映在屏幕上,因为在创建视图之前必须将这个设置提供给滑动面板,这就是为什么相对宽度值在这里不起作用的原因。
    【解决方案2】:

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

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

    希望这会有所帮助。

    【讨论】:

      【解决方案3】:

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

      app:layout_widthPercent="100%"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-14
        • 2022-10-19
        • 2014-05-26
        • 2011-12-22
        • 1970-01-01
        • 2010-10-21
        • 1970-01-01
        • 2013-05-14
        相关资源
        最近更新 更多