第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

列表視圖在ScrollView中沒有在Android上滾動

列表視圖在ScrollView中沒有在Android上滾動

瀟瀟雨雨 2019-05-31 16:30:29
列表視圖在ScrollView中沒有在Android上滾動我的卷軸有問題ListView在一個ScrollView..我有一個在頂部有一些Edittext的活動,然后是一個有兩個選項卡的選項卡主機,每個選項卡都有一個ListView。當(dāng)EditText視圖被聚焦時,軟鍵盤出現(xiàn),當(dāng)我有一個ScrollView時,內(nèi)容是可滾動的。但是,當(dāng)ListViews中有更多的條目(選項卡中的條目)時,我就無法滾動ListView,即使有更多的條目,也會出現(xiàn)問題。以下是布局XML:<?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:background="?backgroundImage"     android:orientation="vertical">   <LinearLayout         android:orientation="horizontal"         android:layout_width="fill_parent"         android:layout_height="50dip"         android:layout_alignParentBottom="true"         android:layout_margin="10dip"         android:id="@+id/buttons">     <Button             android:text="Save"             android:layout_margin="2dip"             android:textSize="20dip"             android:id="@+id/btnSaveorUpdate"             android:layout_height="wrap_content"             android:layout_width="145dip"></Button>     <Button             android:text="Cancel"             android:layout_margin="2dip"             android:textSize="20dip"             android:id="@+id/btnCancelorDelete"             android:layout_height="wrap_content"             android:layout_width="145dip"></Button>   </LinearLayout>   <ScrollView         android:layout_above="@id/buttons"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:fillViewport="true"         android:layout_margin="10dip">     <LinearLayout             android:orientation="vertical"             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:layout_margin="10dip">誰能告訴我這里有什么問題嗎?我還有一篇關(guān)于ListView內(nèi)部ScrollView問題的文章,但它們在我的例子中沒有用。
查看完整描述

3 回答

?
眼眸繁星

TA貢獻1873條經(jīng)驗 獲得超9個贊

你不應(yīng)該把ListView在一個ScrollView因為ListView類實現(xiàn)自己的滾動,只是不接收手勢,因為它們都是由父類處理的。ScrollView..我強烈建議你以某種方式簡化你的布局。例如,可以將希望滾動的視圖添加到ListView作為標(biāo)題或頁腳。

更新:

從API 21級(Lolliop)開始,Android SDK正式支持嵌套滾動容器。有很多方法ViewViewGroup提供此功能的類。要使嵌套滾動在Lolliop上工作,必須為子滾動視圖啟用它,方法是添加android:nestedScrollingEnabled="true"到它的xml聲明或顯式調(diào)用setNestedScrollingEnabled(true).

如果您想在預(yù)Lolliop設(shè)備上進行嵌套滾動操作(您可能會這樣做),則必須使用支持庫中的相應(yīng)實用程序類。首先你必須替換你ScrollView帶著NestedScrollView..后者實現(xiàn)了兩個NestedScrollingParentNestedScrollingchild因此,它可以用作父或子滾動容器。

ListView不支持嵌套滾動,因此需要將其子類并實現(xiàn)NestedScrollingChild..幸運的是,支持庫提供了NestedScrollingChild Helper類,因此您只需創(chuàng)建該類的實例并從視圖類的相應(yīng)方法調(diào)用其方法即可。


查看完整回答
反對 回復(fù) 2019-05-31
?
鴻蒙傳說

TA貢獻1865條經(jīng)驗 獲得超7個贊

我找到了一個很好的解決方案,可以滾動ListView沒有問題:

ListView lv = (ListView)findViewById(R.id.myListView);  // your listview inside scrollviewlv.setOnTouchListener(new ListView.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                // Disallow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(true);
                break;

            case MotionEvent.ACTION_UP:
                // Allow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }

            // Handle ListView touch events.
            v.onTouchEvent(event);
            return true;
        }
    });

這樣做是禁用TouchEventS在.ScrollView并使.ListView攔截他們。它很簡單,而且一直在工作。


查看完整回答
反對 回復(fù) 2019-05-31
?
人到中年有點甜

TA貢獻1895條經(jīng)驗 獲得超7個贊

我也有一個解決辦法。我總是用這種方法。嘗嘗這個

<ScrollView
    android:id="@+id/createdrill_scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="15dp" >

            <net.thepaksoft.fdtrainer.NestedListView
                android:id="@+id/crewList"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_weight="1"
                android:background="@drawable/round_shape"
                android:cacheColorHint="#00000000" >
            </net.thepaksoft.fdtrainer.NestedListView>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="15dp" >

            <net.thepaksoft.fdtrainer.NestedListView
                android:id="@+id/benchmarksList"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_weight="1"
                android:background="@drawable/round_shape"
                android:cacheColorHint="#00000000" >
            </net.thepaksoft.fdtrainer.NestedListView>
        </LinearLayout></ScrollView>

java類:

public class NestedListView extends ListView implements OnTouchListener, OnScrollListener {

    private int listViewTouchAction;
    private static final int MAXIMUM_LIST_ITEMS_VIEWABLE = 99;

    public NestedListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        listViewTouchAction = -1;
        setOnScrollListener(this);
        setOnTouchListener(this);
    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem,
            int visibleItemCount, int totalItemCount) {
        if (getAdapter() != null && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) {
            if (listViewTouchAction == MotionEvent.ACTION_MOVE) {
                scrollBy(0, -1);
            }
        }
    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        int newHeight = 0;
        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        if (heightMode != MeasureSpec.EXACTLY) {
            ListAdapter listAdapter = getAdapter();
            if (listAdapter != null && !listAdapter.isEmpty()) {
                int listPosition = 0;
                for (listPosition = 0; listPosition < listAdapter.getCount()
                        && listPosition < MAXIMUM_LIST_ITEMS_VIEWABLE; listPosition++) {
                    View listItem = listAdapter.getView(listPosition, null, this);
                    //now it will not throw a NPE if listItem is a ViewGroup instance
                    if (listItem instanceof ViewGroup) {
                        listItem.setLayoutParams(new LayoutParams(
                                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                    }
                    listItem.measure(widthMeasureSpec, heightMeasureSpec);
                    newHeight += listItem.getMeasuredHeight();
                }
                newHeight += getDividerHeight() * listPosition;
            }
            if ((heightMode == MeasureSpec.AT_MOST) && (newHeight > heightSize)) {
                if (newHeight > heightSize) {
                    newHeight = heightSize;
                }
            }
        } else {
            newHeight = getMeasuredHeight();
        }
        setMeasuredDimension(getMeasuredWidth(), newHeight);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (getAdapter() != null && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) {
            if (listViewTouchAction == MotionEvent.ACTION_MOVE) {
                scrollBy(0, 1);
            }
        }
        return false;
    }}


查看完整回答
反對 回復(fù) 2019-05-31
  • 3 回答
  • 0 關(guān)注
  • 708 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號