【问题标题】:Android layout for ListView followed by non-scrolling bar of text at bottom of screenListView 的 Android 布局,后跟屏幕底部的非滚动文本栏
【发布时间】:2010-12-22 21:49:34
【问题描述】:

我在设置 Android 布局时遇到问题。

我希望喜欢的是一个可滚动的 ListView,后跟一个不滚动且始终停留在屏幕底部的小文本栏 (TextView)。

看起来像这样:

ListViewItem1

ListViewItem2

ListViewItem3

此处的文本栏(始终显示,与 ListView 的滚动状态无关)

我已经尝试了很多不同的变体,但没有一个显示静态文本

关于我哪里出错了有什么想法吗?

TKS!

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="wrap_content">
        <ListView android:id="@+id/list2" android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>
    <TextView android:layout_width="fill_parent"
        android:layout_height="50dip" android:text="Bar of text that always stays at the bottom of the screen" />
</LinearLayout>

【问题讨论】:

    标签: android listview layout textview


    【解决方案1】:

    使用RelativeLayout。使用android:layout_alignParentBottom="true"TextView 锚定到底部。让ListView 填写剩余部分。

    或者,使用单个LinearLayout,将ListViewandroid:layout_height 设置为0px,将android:layout_weight 设置为1,并在ListView 之后将TextView 设置为@ 的子级987654333@.

    【讨论】:

    • 您的意思是“android:layout_width to 1”还是“android:layout_weight to 1”?
    • @Nemi:感谢您指出这一点——我已经修正了我原来的答案。
    • 我尝试了高度为 0px 和 layout_weight 1 的 LinearLayout 选项,但没有成功。你能发布XML吗?
    • relativeLayout 可以工作,但要放置所有组件需要做太多工作。
    【解决方案2】:

    使用 android:layout_weight 使您的列表视图填充静态文本未使用的页面剩余部分。

    像这样:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout android:orientation="vertical"
            android:layout_width="fill_parent" android:layout_height="wrap_content">
            <ListView android:id="@+id/list2" android:layout_width="fill_parent"
                    android:layout_height="wrap_content" android:layout_weight="1"/><!-- here's the important part-->
        </LinearLayout>
        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:text="Bar of text that always stays at the bottom of the screen" />
    </LinearLayout>
    

    【讨论】:

      【解决方案3】:

      实际上,听起来您确实想使用footer,ListView 已经拥有并且完全按照您的描述进行操作。

      【讨论】:

      • 实际上,addFooterView 似乎可以确保您可以将添加的视图作为列表的最后一个元素,它无助于将其加权到屏幕底部。
      【解决方案4】:

      基于@CommonsWare 的回答:

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">
      
          <ListView android:id="@+id/actionsListView" 
              android:layout_height="0px" 
              android:layout_width="fill_parent"
              android:layout_weight="1"
              android:transcriptMode="alwaysScroll"/>    
      
          <TextView android:text="" 
              android:id="@+id/progressTextLabel" 
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content"
              android:singleLine="true"/>
      
      </LinearLayout>
      

      【讨论】:

        【解决方案5】:

        试试这个:

        希望对你有帮助:

        <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="420dp"
                android:id="@+id/rel">
                <ListView
                    android:id="@+id/list2"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/rel"
                android:layout_alignParentBottom="true">
                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="50dip"
                    android:text="Bar of text that always stays at the bottom of the screen" />
            </RelativeLayout>
        </RelativeLayout>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-02-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-08-19
          相关资源
          最近更新 更多