【问题标题】:Custom dialog with listview and button always fullscreen带有列表视图和按钮的自定义对话框始终全屏
【发布时间】:2011-06-08 21:47:28
【问题描述】:

我想创建一个自定义对话框,其中包含列表视图和列表视图下方的按钮。按钮应位于列表视图下方,但始终可见 (layout_alignParentBottom="true")。

我创建了一个运行良好的 xml,但仅限于长列表。如果列表很短,按钮仍然在屏幕底部,并且对话框标题的高度被拉伸以使对话框填满屏幕。所附图片显示了我今天得到的结果。

简而言之。我想要一个仅在必要时才填满屏幕的普通对话框。

由于某种原因,我无法发布 xml。但我使用相对布局,按钮对齐父底部,小面板布局在按钮上方,列表视图布局在此面板上方。 所有布局都是 layout:height=wrap_content。

感谢您的帮助。 /马格纳斯

【问题讨论】:

    标签: android listview button dialog android-alertdialog


    【解决方案1】:

    问题解决了。

    我从android源代码中取出alert_dialog.xml并稍作修改。我将我的列表视图添加到 customPanel 框架布局,删除了 topPanel 和 contentPanel。

    结果:对话框不大于内容,最大与屏幕一样大,按钮始终可见。

    【讨论】:

      【解决方案2】:

      回复@Fresh_Meat

      您可以像这样将按钮添加到列表视图的底部: http://www.anddev.org/code-snippets-for-android-f33/listview-with-a-footer-item-t49281.html

      <?xml version="1.0" encoding="utf-8"?>
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:padding="10dip"
         >
          <LinearLayout
              android:id="@+id/bottom_view"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentBottom="true">
                  <!--Put whatever view item you want here -->
                  <EditText
                   android:id="@+id/conversation_reply"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:text="write a reply..."
                   />
         </LinearLayout>
         <ListView
          android:id="@+id/android:list"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:cacheColorHint="#00000000"
          android:layout_above="@id/bottom_view"
          />
      </RelativeLayout>
      

      在您的警报视图中使用它

      【讨论】:

        【解决方案3】:

        This answer 通常是正确的,但由于有许多嵌套布局,会带来很大的开销。

        您需要的是一个简单的LinearLayout 并带有特定的配置:

        <ListView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
             />
        <!-- Notice layout_weight=1 and height=0dp - it's the most important thing here-->
        
        
        <WhateverLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        <!-- And the layout below the listview has some arbitrary height (but no weight!)-->
        
        </WhateverLayout>
        
        </LinearLayout>
        

        结果是一样的:“对话框不大于内容,最大与屏幕一样大,按钮始终可见。”

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-06-19
          • 2012-06-15
          • 1970-01-01
          • 1970-01-01
          • 2012-04-27
          • 2015-03-16
          • 1970-01-01
          相关资源
          最近更新 更多