Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 添加fillViewport=true后,具有ListView的ScrollView不可滚动_Android_Listview_Scrollview - Fatal编程技术网

Android 添加fillViewport=true后,具有ListView的ScrollView不可滚动

Android 添加fillViewport=true后,具有ListView的ScrollView不可滚动,android,listview,scrollview,Android,Listview,Scrollview,我已将fillViewport设置为true,以使ListView具有正确的大小,但这会导致ScrollView无法滚动。 如果我对listView使用固定大小,它就可以工作,但我不希望listView是可滚动的 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width=

我已将fillViewport设置为true,以使ListView具有正确的大小,但这会导致ScrollView无法滚动。 如果我对listView使用固定大小,它就可以工作,但我不希望listView是可滚动的

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.example.pascal.x"
android:background="#FFFFFF">

<!-- TODO: Update blank fragment layout -->

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

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="+ add stuff"
        android:id="@+id/button"
        android:background="#00AEEF"
        android:textColor="#FFF"
        android:layout_gravity="center_horizontal|top" />

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:fillViewport="false"
        android:layout_gravity="center_horizontal|bottom"
        android:scrollbars="vertical"
        android:id="@+id/scrollView" >

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

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="15dp"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="stuff"
                android:id="@+id/textView"
                android:textColor="#00AEEF" />

            <ListView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="15dp"
                android:id="@+id/listView"
                android:layout_gravity="center_horizontal" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="15dp"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="other stuff"
                android:id="@+id/textView2"
                android:textColor="#00AEEF" />

            <ListView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="15dp"
                android:id="@+id/listView2" />

        </LinearLayout>
    </ScrollView>
</LinearLayout>


我在这里找到了解决问题的方法:

公共类实用程序{
公共静态无效setListViewHeightBasedOnChildren(ListView ListView){
ListAdapter ListAdapter=listView.getAdapter();
如果(listAdapter==null){
//前提条件
返回;
}
int totalHeight=listView.getPaddingTop()+listView.getPaddingBottom();
对于(int i=0;i
我在这里找到了解决问题的方法:

公共类实用程序{
公共静态无效setListViewHeightBasedOnChildren(ListView ListView){
ListAdapter ListAdapter=listView.getAdapter();
如果(listAdapter==null){
//前提条件
返回;
}
int totalHeight=listView.getPaddingTop()+listView.getPaddingBottom();
对于(int i=0;i
我在这里找到了解决问题的方法:

公共类实用程序{
公共静态无效setListViewHeightBasedOnChildren(ListView ListView){
ListAdapter ListAdapter=listView.getAdapter();
如果(listAdapter==null){
//前提条件
返回;
}
int totalHeight=listView.getPaddingTop()+listView.getPaddingBottom();
对于(int i=0;i
我在这里找到了解决问题的方法:

公共类实用程序{
公共静态无效setListViewHeightBasedOnChildren(ListView ListView){
ListAdapter ListAdapter=listView.getAdapter();
如果(listAdapter==null){
//前提条件
返回;
}
int totalHeight=listView.getPaddingTop()+listView.getPaddingBottom();
对于(int i=0;i
使用此视图而不是listview

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ListView;

public class ExpandableListView extends ListView {

boolean expanded = true;

public ExpandableListView(Context context) {
    super(context);
}

public ExpandableListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

    public ExpandableListView(Context context, AttributeSet attrs, int  defStyle)       
{
    super(context, attrs, defStyle);
}

public boolean isExpanded() {
    return expanded;
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // HACK! TAKE THAT ANDROID!
    if (isExpanded()) {
        // Calculate entire height by providing a very large height hint.
        // View.MEASURED_SIZE_MASK represents the largest height possible.
        int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,   MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    } else {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}




}
在XML中使用它

<yourpackagename(where you put this file).ExpandableListView
 .....
 .....
 ...../>

使用此视图而不是listview

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ListView;

public class ExpandableListView extends ListView {

boolean expanded = true;

public ExpandableListView(Context context) {
    super(context);
}

public ExpandableListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

    public ExpandableListView(Context context, AttributeSet attrs, int  defStyle)       
{
    super(context, attrs, defStyle);
}

public boolean isExpanded() {
    return expanded;
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // HACK! TAKE THAT ANDROID!
    if (isExpanded()) {
        // Calculate entire height by providing a very large height hint.
        // View.MEASURED_SIZE_MASK represents the largest height possible.
        int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,   MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    } else {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}




}
在XML中使用它

<yourpackagename(where you put this file).ExpandableListView
 .....
 .....
 ...../>

使用此视图而不是listview

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ListView;

public class ExpandableListView extends ListView {

boolean expanded = true;

public ExpandableListView(Context context) {
    super(context);
}

public ExpandableListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

    public ExpandableListView(Context context, AttributeSet attrs, int  defStyle)       
{
    super(context, attrs, defStyle);
}

public boolean isExpanded() {
    return expanded;
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // HACK! TAKE THAT ANDROID!
    if (isExpanded()) {
        // Calculate entire height by providing a very large height hint.
        // View.MEASURED_SIZE_MASK represents the largest height possible.
        int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,   MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    } else {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}




}
在XML中使用它

<yourpackagename(where you put this file).ExpandableListView
 .....
 .....
 ...../>

使用此视图而不是listview

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ListView;

public class ExpandableListView extends ListView {

boolean expanded = true;

public ExpandableListView(Context context) {
    super(context);
}

public ExpandableListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

    public ExpandableListView(Context context, AttributeSet attrs, int  defStyle)       
{
    super(context, attrs, defStyle);
}

public boolean isExpanded() {
    return expanded;
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // HACK! TAKE THAT ANDROID!
    if (isExpanded()) {
        // Calculate entire height by providing a very large height hint.
        // View.MEASURED_SIZE_MASK represents the largest height possible.
        int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,   MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    } else {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}




}
在XML中使用它

<yourpackagename(where you put this file).ExpandableListView
 .....
 .....
 ...../>


根据listview中可用的子视图数动态设置listview的高度。根据listview中可用的子视图数动态设置listview的高度。根据listview中可用的子视图数动态设置listview的高度。设置listview的高度动态地基于listview中可用的子视图的数量。