【问题标题】:Android listview footer doesn't fit properlyAndroid listview 页脚不适合
【发布时间】:2014-01-29 19:07:45
【问题描述】:

我的以下布局受接受的答案here的影响

list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg"
    android:orientation="vertical" >
    ....
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <include
            android:id="@+id/footer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            layout="@layout/footer" />
        <ListView
            android:id="@+id/song_list_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@id/footer"
            android:layout_gravity="center_horizontal"
            android:layoutAnimation="@anim/list_animation"
            android:listSelector="@drawable/bg_list_row_song" />
    </RelativeLayout>
</LinearLayout>

和footer.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

        <ImageView
            android:id="@+id/img_ad"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/adv" />

</LinearLayout>

生成这张图片

我的问题是我想要布局末尾的页脚和填充宽度,然后保持高度以使图像填充真实的移动屏幕宽度。我可以通过设置某个列表高度来做到这一点,但不希望它支持更长的屏幕。

有没有办法先计算页脚宽度并在其位于布局底部时保持其高度,然后将剩余高度分配给列表?以及如何?

编辑

感谢您的回答,我已经找到了最好的方法,我将图像缩放到比设备屏幕更宽,并且我使用了

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:adjustViewBounds="true"
        android:src="@drawable/adv" />

    <ListView
        android:id="@+id/song_list_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/footer"
        android:layoutAnimation="@anim/list_animation"
        android:listSelector="@drawable/bg_list_row_song" />
</RelativeLayout>

【问题讨论】:

    标签: android android-layout android-ui


    【解决方案1】:

    1 - 在页脚 xml 中,您不会匹配父大小,而是包装其内容。
    2 - ListView 高度应该与剩余的父级大小匹配。

    所以,只需交换这两个高度属性,它就会完美地工作。

    【讨论】:

      【解决方案2】:
      // try this way
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:padding="5dp"
          android:background="@drawable/bg"
          android:orientation="vertical" >
      
          <ListView
              android:id="@+id/song_list_view"
              android:layout_width="match_parent"
              android:layout_height="0dp"
              android:layout_weight="1"
              android:layoutAnimation="@anim/list_animation"
              android:listSelector="@drawable/bg_list_row_song"/>
      
          <include
              android:id="@+id/footer"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="5dp"
              layout="@layout/list_item" />
      
      </LinearLayout>
      
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:gravity="center"
          android:layout_height="wrap_content"
          android:orientation="vertical" >
      
          <ImageView
              android:id="@+id/img_ad"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:adjustViewBounds="true"
              android:src="@drawable/adv" />
      
      </LinearLayout>
      

      【讨论】:

        【解决方案3】:
        <?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"
            android:orientation="vertical" >
        
            <ListView
                android:id="@+id/list"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:cacheColorHint="#00000000" />
           <ImageView 
               android:id="@+id/img1"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:layout_alignParentBottom="true"
               android:background="@drawable/ic_launcher"
        
               />
        
        </RelativeLayout>
        

        试试这个,也许对你有帮助。

        【讨论】:

          【解决方案4】:
          <?xml version="1.0" encoding="utf-8"?>
          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical" >
          
              <LinearLayout
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_weight="1"
                  android:orientation="vertical"
                  android:background="#EE4566" >
          
              <!-- add list view here  -->
          
              </LinearLayout>
          
              <LinearLayout 
                  android:layout_width="fill_parent"
                  android:layout_height="50dp"
                  android:orientation="vertical" >
          
               <!-- add footer here  -->
          
          </LinearLayout>
          

          【讨论】:

            猜你喜欢
            • 2012-01-01
            • 1970-01-01
            • 2014-07-07
            • 2014-08-02
            • 2015-09-11
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-03-14
            相关资源
            最近更新 更多