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捕獲了一切。 –