【问题标题】:Click on Item Wrapped in ScrollView Inside ListView点击ListView里面的ScrollView中包裹的Item
【发布时间】:2014-08-26 21:48:48
【问题描述】:

我尝试在布局中结合图像和文本。我在滚动视图中创建布局,滚动视图本身在 ListView 中。 看起来文本可以滚动(因为文本很长)并且问题解决了。但是当我尝试单击列表视图中的项目时会出现新问题。 好像不能点击。因为当我删除包装文本的滚动视图时,它可以为其中的项目调用侦听器事件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"   
android:background="@color/hijau_tua"    
 >

<ImageView 
        android:id="@+id/flag"
        android:layout_width="125dp"
        android:layout_height="80dp"
        android:layout_gravity="top"
        />

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

        <TextView 
            android:id="@+id/txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/white"
            android:textSize="15dp"             
        />          

        <TextView 
            android:id="@+id/cur"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/white"
            android:textSize="12dp"        
        />

    </LinearLayout>
    </ScrollView>

这是显示图像和文本视图的布局。我将它(TextView)包装在 ScrollView 中。 (仍然,我单击其中一项,没有响应。)

请指出我的问题。 谢谢

【问题讨论】:

  • 你的意思是上面的布局是列表视图中的行?
  • ^ 那是工作。但它只有在我触摸图像时才有效。但是当我触摸包裹在滚动视图中的 LinearLayout 时不起作用

标签: android android-layout listview layout android-listview


【解决方案1】:

我有同样的问题。 ScrollView 中有许多针对 ListView 的修复。问题是他们不会点击孩子。唯一对我有用的解决方案是将 ScrollView 替换为:

公共类 VerticalScrollview 扩展 ScrollView {

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

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

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

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = ev.getAction();
    switch (action)
    {
        case MotionEvent.ACTION_DOWN:
                Log.i("VerticalScrollview", "onInterceptTouchEvent: DOWN super false" );
                super.onTouchEvent(ev);
                break;

        case MotionEvent.ACTION_MOVE:
                return false; // redirect MotionEvents to ourself

        case MotionEvent.ACTION_CANCEL:
                Log.i("VerticalScrollview", "onInterceptTouchEvent: CANCEL super false" );
                super.onTouchEvent(ev);
                break;

        case MotionEvent.ACTION_UP:
                Log.i("VerticalScrollview", "onInterceptTouchEvent: UP super false" );
                return false;

        default: Log.i("VerticalScrollview", "onInterceptTouchEvent: " + action ); break;
    }

    return false;
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    super.onTouchEvent(ev);
    Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() );
     return true;
}

}

【讨论】:

    【解决方案2】:

    listview 项内的 Scrollview 示例在下面的链接中给出,因此请选择此链接。 它将帮助你如何实现scrollview scroll insdie listview

    这是链接:

    Scroll view is not working in list view

    【讨论】:

    • 您的链接根本没有帮助。
    猜你喜欢
    • 1970-01-01
    • 2017-05-05
    • 1970-01-01
    • 2016-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多