listview的item 是horizontalscrollview ,horizontalscrollvi

Android 码拜 8年前 (2016-05-12) 890次浏览
listview的item 是horizontalscrollview ,horizontalscrollview 里面包含button,item现在无法实现监,布局文件里面已经加入的    android:descendantFocusability=”blocksDescendants”,但是依旧无法点击。onTouch在listview里面根本无法显示坐标点,怎么决解啊。求高手啊指点啊。
解决方案

40

package com.example.listviewforscrollview;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;
//次控制是Scrollview,子控件是Listview。
public class ListViewForScrollView extends ListView
{
public ListViewForScrollView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public ListViewForScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ListViewForScrollView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
@Override
/**
* 重写该方法,达到使ListView适应ScrollView的效果
*/
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}

<!–这个是垂直滑动 –>
<com.example.gridviewforscrollview.GridViewForScrollView
android:id=”@+id/listview
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:layout_marginBottom=”50dp”
android:background=”#DCDCDC”
android:horizontalSpacing=”1dp”
android:verticalSpacing=”1dp”
android:numColumns=”4″
android:text=”@string/hello_world” />
这样就可以监听点击事件了。


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明listview的item 是horizontalscrollview ,horizontalscrollvi
喜欢 (0)
[1034331897@qq.com]
分享 (0)