簡體   English   中英

如何使 Android ExpandableListView 不可滾動?

[英]How to make Android ExpandableListView not scrollable?

我無法弄清楚如何使 ExpandableListView 不可滾動,始終處於全尺寸並定位在布局的底部,而且還保持在 textView 超出范圍時滾動的能力。 我知道不建議在 ScrollView 中使用 ListView。 但如何實現這一目標? 現在一切看起來像這樣:

在此處輸入圖片說明

布局:

在此處輸入圖片說明

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="16dp">
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:srcCompat="@mipmap/ic_launcher"
            android:id="@+id/imageView2" />

        <TextView
            android:text="Order description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/imageView2"
            android:id="@+id/orderDescr"
            android:paddingTop="5dp" />
    </RelativeLayout>
</ScrollView>

<TextView
    android:text="label"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textView5"
    android:paddingTop="15dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp" />

<ExpandableListView
    android:id="@+id/expandableListView"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:indicatorLeft="?
    android:attr/expandableListPreferredItemIndicatorLeft"
    android:childDivider="#00000000"
    android:layout_below="@+id/orderDescr"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="5dp"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:headerDividersEnabled="false"
    android:footerDividersEnabled="false"
    android:isScrollContainer="false" />

</LinearLayout>

它對我有用

ExpandableListView lv = (Expandable) findViewById(R.id.layout_lv);
lv.setOnTouchListener(new OnTouchListener() {
// Setting on Touch Listener for handling the touch inside ScrollView
@Override
public boolean onTouch(View v, MotionEvent event) {
// Disallow the touch request for parent scroll on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM