Java Android-ListView';s的高度正好适合1个ListView项

Java Android-ListView';s的高度正好适合1个ListView项,java,android,xml,listview,layout,Java,Android,Xml,Listview,Layout,我正在与Android Studio合作,并设计如下布局。但是,我的ListView lv_漫画只显示一个项目的足够空间。我尝试将布局高度设置为填充父对象,但仍然不起作用。但是,当我将layout_height设置为特定大小时,这是可以的,但当我切换到另一个屏幕大小时,这并不好。有人能帮我吗 <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/andr

我正在与Android Studio合作,并设计如下布局。但是,我的ListView lv_漫画只显示一个项目的足够空间。我尝试将布局高度设置为填充父对象,但仍然不起作用。但是,当我将layout_height设置为特定大小时,这是可以的,但当我切换到另一个屏幕大小时,这并不好。有人能帮我吗

<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/layout_swiperefresh"
android:background="@color/grey">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="vertical">
            <TextView
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:text="Latest Update"
                android:textColor="@color/white"
                android:background="@color/indigo_main"
                android:textSize="10dp"/>
            <Gallery
                android:id="@+id/gallery1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:text="Most Popular"
                android:textColor="@color/white"
                android:background="@color/indigo_main"
                android:textSize="10dp"/>
            <Gallery
                android:id="@+id/gallery2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>

        <TextView
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:text="New Manga"
            android:textColor="@color/white"
            android:background="@color/indigo_main"
            android:textSize="10dp"/>
        <ListView
                android:drawSelectorOnTop="true"
                android:layout_width="match_parent"
                android:layout_height="fill_parent"
                android:id="@+id/lv_comics" />

    </LinearLayout>
</ScrollView>

尝试使用此选项动态计算高度

public static void setListViewHeight(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return;
    }
    int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.AT_MOST);
    int totalHeight = 0;
    View view = null;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        view = listAdapter.getView(i, view, listView);
        if (i == 0) {
            view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT));
        }
        view.measure(desiredWidth, MeasureSpec.AT_MOST);
        totalHeight += view.getMeasuredHeight();
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}
public静态无效setListViewHeight(ListView ListView){
ListAdapter ListAdapter=listView.getAdapter();
如果(listAdapter==null){
返回;
}
int desiredWidth=MeasureSpec.makeMeasureSpec(listView.getWidth(),最多测量一次);
int totalHeight=0;
视图=空;
对于(int i=0;i
列表视图
内部
滚动视图
。。。?不是个好主意。滚动视图中的Listview不是个好主意。为了解决这个问题,您可以将两个视图作为标题添加到listview中