1

取代我有以下问题: public class MainActivity extends FragmentActivity implements ActionBar.TabListener列表视图仍然可点击,即使是通过点击片段

这是通过使用ViewPager: 我开发使用的应用程序。因此,最初的main_activity.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:fadingEdge="none" > 

    <FrameLayout 
     android:id="@+id/main_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <android.support.v4.view.ViewPager 
      android:id="@+id/pager" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 
    </FrameLayout> 

    <FrameLayout 
     android:id="@+id/fragment_container" 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" > 
    </FrameLayout> 

</RelativeLayout> 

和framgent_container.xml包含以下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/items_list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/adv_image" 
     android:layout_width="fill_parent" 
     android:layout_height="56dp" 
     android:src="@drawable/no_adv" /> 

    <ListView 
     android:id="@id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/adv_image" /> 

</RelativeLayout> 

因此,这里的问题: 我得到的名单显示正确,并在它上面的adv_image。当我点击我的列表中的一个项目时,我可以看到它应该显示的项目。 (在滚动视图中是具有图像视图和下方描述的线性布局)。 但是 当我点击图片视图(这是不可点击)! 显示先前列表中的另一项。这让我认为Listview仍然存在(在我的文章后面?很奇怪)。即使我点击了文章图片上方的一点点,它也会触发adv_image url,该url只存在于listview中,并且不在此片段内。

用文章片段替换列表视图的代码如下。

public class ArticlesListFragment extends ListFragment { 

这onCreateView膨胀以下

View rootView = inflater.inflate(R.layout.items_list, container, false); 

它具有以下功能

@Override 
public void onListItemClick(ListView l, View v, int position, long id) { 

    Fragment fragment = null; 
    Bundle args = new Bundle(); 

    fragment = new Article(); 

    args.putString("unique_id", ((ArticleItem) v.getTag()).ID); 

    fragment.setArguments(args); 

    FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); 
    ft.addToBackStack("HomePage"); 
    ft.replace(R.id.fragment_container, fragment); 
    ft.commit(); 

} 

所以任何想法?????我试图取代几个不同的东西onitemclick ..但我仍然没有运气..

在此先感谢!

+0

你是在另一个'Fragment'的顶部添加一个'Fragment'吗?一个'Fragment'顶部的ImageView?或在ListView顶部的ImageView? – Emmanuel

+0

我有一个FragmentList,它包含一个ListView顶部的imageView,并且一个片段替代了片段列表。这个新的片段包含一个ImageView和一个TextView下面。 –

回答

0

稍后出现在XML中的元素将被放置得更高,因此在上面显示的XML中,ListView将出现在ImageView上方。如果您希望ImageView处于最佳位置,请交换订单。

无关笔记:

1)fill_parent是相同的match_parent(但match_parent是首选)

2)您只需要在它在AXML遇到的第一个机会与+前缀的ID(你已经做了两次adv_image)。

+0

它是有道理的..我不知道它..我现在检查:) –

+1

嗯,我试图通过设置相对布局中的片段视图,并添加layout_above先前的元素,但它没有做的伎俩。我设法通过将所有新的片段设置为Scrollview来解决这个问题,它看起来总是位于其他元素之上。: - /也谢谢关于无关的笔记,应用的更改:) –

+0

很高兴您对它进行了整理:)所以也许有可能是触摸通过最上面的图像视图,但是ScrollView捕获了一切。 –