2017-07-14 73 views
0

我有2个视图。 1)MyMenuRestaurent.axml 2)ImageAndSubTitle.axml滚动视图中的Listview不可点击

为MyMenuRestaurent.axml

<LinearLayout> 
<ListView> 
</ListView> 
</LinearLayout> 

代码用于图像和副标题码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/lightgray"> 
    <ScrollView 
    xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
    <TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:stretchColumns="1" 
     android:backgroundTint="#ff81d4fa"> 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingLeft="10dip"> 
     </LinearLayout> 

     <TextView 
      android:id="@+id/Text1" 
      android:text="Demo Item Name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="@color/blue" 
      android:textSize="20dip" /> 
     <TextView 
      android:id="@+id/Text2" 
      android:text="Demo Price" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="14dip" 
      android:textColor="@color/blue" /> 
    </TableLayout> 
    </ScrollView>  
</LinearLayout> 

我有列表视图点击。当点击一个项目时,单个项目的细节被打开。但如果我添加滚动视图(单击)不起作用。因为滚动视图块单击元素。我想使滚动视图一起点击项目。

+0

你有没有解决问题了吗? –

+0

unfortunatley不! – DevKriya

+0

那么,有什么问题?你能否详细说明一下,以便我可以帮你解决这个问题? –

回答

0

尝试添加android:descendantFocusability="blocksDescendants"LinearLayout,它可能看起来像:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/lightgray" 
    android:descendantFocusability="blocksDescendants"> 

希望它能帮助。

+0

您的解决方案无法正常工作! – DevKriya

0

对于自定义列表视图,你必须有一个适配器,你会传递一个自定义视图。因此,将onClickListener放在适配器中的自定义视图的父级布局上,它将模仿列表视图的onItemClickListener

让这对列表视图

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:id="@+id/linearLayout" 
      android:layout_width="match_parent" 
      android:layout_height="120dp" 
      > 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/list_image" 
    android:src="@drawable/homeopathy" 
    android:scaleType="centerCrop" 
    android:tint="#7b000000" 
    /> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="20dp" 
    android:layout_marginTop="-67dp" 
    android:gravity="center" 
    android:textColor="#ffffff" 
    android:textSize="15dp" 
    android:text="This is a sample text" 
    android:id="@+id/title" 
    /> 

    </LinearLayout> 

,并在适配器

public View getView(int position, View convertView, ViewGroup parent) { 

     View vi = inflater.inflate(R.layout.list_row, null); 

    TextView title = (TextView) vi.findViewById(R.id.title); 

    ImageView thumb_image=(ImageView) vi.findViewById(R.id.list_image); 
    list= data.get(position); 

    // Setting all values in listview 
    title.setText(list.getTitle()); 
    imageLoader.DisplayImage(list.getImage()); 

    LinearLayout linLayout = (LinearLayout) vi.findViewById(R.id.linearLayout); 

    linLayout.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      //Do what you want to do 
     } 
    }); 


    return vi; 
} 
+0

任何演示?或示例代码? – DevKriya

+0

我已经更新了答案,请检查。 –

0

因为元素上滚动视框点击您的自定义视图。我想使滚动视图一起点击项目。

你可以写一个自定义的ListView并覆盖其OnInterceptTouchEvent方法从ScrollView获得触摸事件。

实施此方法来拦截所有触摸屏幕动作事件。这允许您在事件发送给您的孩子时观看事件,并在任何时候掌握当前手势的所有权。

这样的代码:

public class InnerListview : ListView 
{ 
    ... 

    public override bool OnInterceptTouchEvent(MotionEvent ev) 
    { 
     switch (ev.Action) 
     { 
      case MotionEventActions.Down: 
       setParentScrollAble(false); 
       break; 
      case MotionEventActions.Move: 
       break; 
      case MotionEventActions.Up: 
      case MotionEventActions.Cancel: 
       setParentScrollAble(true); 
       break; 
     } 
     return base.OnInterceptTouchEvent(ev); 
    } 

    private void setParentScrollAble(bool flag) 
    { 
     Parent.RequestDisallowInterceptTouchEvent(!flag); 
    } 
} 

使用此ListView.axml这样的:

<ListViewInScrollView.InnerListview 
    android:id="@+id/lv3" 
    android:layout_width="match_parent" 
    android:layout_height="300dp" 
    android:background="#ffffff" /> 
+0

@DevKriya,你解决了你的问题? –