首页 > 解决方案 > 带有 ListView 的 SwipeRefreshLayout 占用了所有可用空间

问题描述

本来以为不用写到这里的,但是解决不了问题!我有一个ListView,有wrap_content,在它下面TabLayoutViewPager。一切正常,layout当我填充时正确对齐ListView

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

  <LinearLayout
    android:id="@+id/headerTable"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/text_modena"
        android:layout_width="20dp"
        android:layout_height="30dp"
        android:layout_weight="0.7"
        android:background="@drawable/table_border"
        android:gravity="center"
        android:text="@string/table11"
        android:textColor="#000000"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/text_saldo"
        android:layout_width="20dp"
        android:layout_height="30dp"
        android:layout_weight="0.7"
        android:background="@drawable/table_border"
        android:gravity="center"
        android:text="@string/table12"
        android:textColor="#000000"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/text_pagar"
        android:layout_width="20dp"
        android:layout_height="30dp"
        android:layout_weight="0.7"
        android:background="@drawable/table_border"
        android:gravity="center"
        android:text="@string/table13"
        android:textColor="#000000"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/text_cobrar"
        android:layout_width="20dp"
        android:layout_height="30dp"
        android:layout_weight="0.7"
        android:background="@drawable/table_border"
        android:gravity="center"
        android:text="@string/table14"
        android:textColor="#000000"
        android:textSize="14sp" />
</LinearLayout>

<ListView
    android:id="@+id/listViewTrefi"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/headerTable" />

<View
    android:id="@+id/divider2"
    style="@style/dividerMain"
    android:layout_width="match_parent"
    android:layout_height="4dp"
    android:layout_below="@+id/listViewTrefi"
    android:alpha="0.5" />

<android.support.design.widget.TabLayout
    android:id="@+id/sliding_tabs"
    style="@style/SlidingTabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/divider2"
    app:tabMode="fixed"
    app:tabTextAppearance="@style/MyTabLayoutTextAppearance" />

<wales.dahoum.mipyme.NonSwipeableViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/sliding_tabs" />

</RelativeLayout>

但是当我尝试换行时ListView,占用所有可用空间SwipeRefreshLayoutlayout is并隐藏它下面的其他视图 -TabLayout并且ViewPager

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:id="@+id/headerTable"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/text_modena"
        android:layout_width="20dp"
        android:layout_height="30dp"
        android:layout_weight="0.7"
        android:background="@drawable/table_border"
        android:gravity="center"
        android:text="@string/table11"
        android:textColor="#000000"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/text_saldo"
        android:layout_width="20dp"
        android:layout_height="30dp"
        android:layout_weight="0.7"
        android:background="@drawable/table_border"
        android:gravity="center"
        android:text="@string/table12"
        android:textColor="#000000"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/text_pagar"
        android:layout_width="20dp"
        android:layout_height="30dp"
        android:layout_weight="0.7"
        android:background="@drawable/table_border"
        android:gravity="center"
        android:text="@string/table13"
        android:textColor="#000000"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/text_cobrar"
        android:layout_width="20dp"
        android:layout_height="30dp"
        android:layout_weight="0.7"
        android:background="@drawable/table_border"
        android:gravity="center"
        android:text="@string/table14"
        android:textColor="#000000"
        android:textSize="14sp" />
</LinearLayout>

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipe_refresh"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/headerTable">

    <ListView
        android:id="@+id/listViewTrefi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>

<View
    android:id="@+id/divider2"
    style="@style/dividerMain"
    android:layout_width="match_parent"
    android:layout_height="4dp"
    android:layout_below="@+id/swipe_refresh"
    android:alpha="0.5" />

<android.support.design.widget.TabLayout
    android:id="@+id/sliding_tabs"
    style="@style/SlidingTabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/divider2"
    app:tabMode="fixed"
    app:tabTextAppearance="@style/MyTabLayoutTextAppearance" />

<wales.dahoum.mipyme.NonSwipeableViewPager
    android:id="@+id/viewPager"
    android:layout_below="@id/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</RelativeLayout>

这是正确的(左)和坏的(右)对齐:

右对齐 不好的对齐

你有什么建议来解决这个问题?

标签: androidlistviewswiperefreshlayout

解决方案


推荐阅读