【问题标题】:Listview still clickable even though is replaced by clicked fragment即使被点击的片段替换,Listview 仍然可以点击
【发布时间】:2014-05-20 15:26:41
【问题描述】:

我有以下问题: 我正在使用以下方式开发应用程序: 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,它只存在于 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..但我仍然没有任何运气..

提前致谢!

【问题讨论】:

  • 您是否在另一个Fragment 之上添加FragmentImageView 位于 Fragment 之上?还是在ListView 之上的ImageView
  • 我有一个 FragmentList,它在 ListView 的顶部包含一个 imageView,并且一个 Fragment 的点击项替换了片段列表。这个新片段包含一个 ImageView 和一个 TextView 下方。

标签: android android-fragments android-listview android-viewpager


【解决方案1】:

稍后出现在 XML 中的元素将被放置在更高的位置,因此在上面显示的 XML 中,ListView 将出现在 ImageView 上方。如果您希望 ImageView 位于顶部,则交换它们的顺序。

无关注释:

1) fill_parentmatch_parent 相同(但首选 match_parent

2) 您只需在第一次在 AXML 中遇到 id 时加上 + 前缀(您已经为 adv_image 做了两次)。

【讨论】:

  • 有道理..我不知道..我现在会检查:)
  • 好吧,我试图通过在相对布局中设置片段视图并在之前的元素之上添加 layout_above 来完成这项工作,但它没有成功。我设法通过将所有新片段设置为 Scrollview 来解决这个问题。它似乎总是在其他元素之上。 :-/ 也感谢不相关的注释,应用的更改:)
  • 很高兴你把它整理出来 :) 所以触摸可能会通过最上面的图像视图,但 ScrollViews 会捕获所有内容。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-05-14
  • 2021-04-07
  • 2020-08-02
  • 1970-01-01
  • 2019-06-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多