【问题标题】:listview and slidingdrawer gives errorlistview 和slidingdrawer 给出错误
【发布时间】:2012-08-09 09:55:26
【问题描述】:

我有这个问题两天了,我找不到任何解决方案。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ListView
    android:id="@+id/presentation_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</ListView>

<SlidingDrawer
    android:id="@+id/slidingDrawer1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/presentation_list"
    android:content="@+id/content"
    android:handle="@+id/handle"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/handle"
        android:layout_width="40dp"
        android:layout_height="fill_parent"
        android:background="@android:color/darker_gray" />

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/content_imageview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/black" />
    </LinearLayout>
</SlidingDrawer>

我有一个非常简单的布局,带有 listviewslidingdrawer,我想通过 listview 来。当我打开我的activity 时没有任何信息,它显示完美无一例外。

但是当我的listview 中有一个项目时,我的slidingdrawer 给出了一个例外。

   AndroidRuntime(4722): java.lang.RuntimeException: SlidingDrawer cannot have UNSPECIFIED dimensions

我已经为此搜索了很多次解决方案,但没有一个对我有用。

有没有人对我有出色的突破?非常感谢!

【问题讨论】:

  • 我的布局现在有效,更新了我的问题以匹配布局。

标签: android listview dimensions slidingdrawer


【解决方案1】:

只是想一想......如果您为滑动抽屉内的 content_imageview 定义精确尺寸会发生什么。

从查看您的代码和 Android 文档 http://developer.android.com/reference/android/widget/SlidingDrawer.html 来看,这似乎是唯一的区别。

可能值得阅读 http://developer.android.com/reference/android/view/View.html 以更好地了解 UNSPECIFIED 以及它在 MeasureSpec 中的使用方式。

还要查看为手柄组件指定设置尺寸。

关于您定义的布局,您最好将滑动抽屉指定为 alignParentBottom 并在滑动抽屉上方对齐列表视图。在一个简短的列表中,您的滑动抽屉将位于布局的一半......

【讨论】:

    【解决方案2】:

    在相对布局中为您的android:layout_height 指定一个数字(例如 600 dip)。当滑动抽屉布局高度为match_parent时,它会跟随布局高度为fill_parent的相对布局,这将导致您的滑动抽屉无限。

    【讨论】:

      【解决方案3】:

      我认为您必须在 LinearLayout 内定义 SlidingDrawer 而不是相反。

      【讨论】:

      • 不,不是这样,那个linearlayout代表我的slidingdrawer的内容。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多