2013-10-06 50 views
0

對於ListViews來說,我很新,那就是開始。ListActivity上的Android固定標題

無論如何,我想要做什麼,顯然是持有一個按鈕或任何在我的列表頂部,這是以編程方式創建,只有一個XML文件。 xml文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    tools:context=".Main" > 


    <ImageView 
     android:id="@+id/picID" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingBottom="10dp" 
     android:paddingRight="10dp" 
     android:paddingTop="10dp" /> 

    <LinearLayout 
     android:id="@+id/LinearLayout2" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/eventName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="18sp" /> 

     <TextView 
      android:id="@+id/eventTime" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_marginRight="5dp" 
      android:textSize="16sp" /> 
    </LinearLayout> 

</LinearLayout> 

然後在Main.java我只是定義我ListAdapter

SimpleAdapter adapter = new SimpleAdapter(Main.this, fillMaps, 
        R.layout.main, from, to); 
      setListAdapter(adapter); 

所以基本上我沒有在我的XML文件中的<ListView/>

+0

我不清楚你想要什麼。固定在您的活動或自定義列表視圖頂部的按鈕? –

+0

@RohanKandwal我很抱歉不清楚。我想要一個固定在頂部的按鈕。也就是說,如果我滾動我的生成列表,按鈕將保持在頂部。 – user2367219

+0

你需要在列表視圖中填充該佈局。 – KOTIOS

回答

0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#F2B1DBF3" 
    android:orientation="vertical" > 
<Button 
android:layout_alignParentTop="true" 
android:id="@+id/button" 
.. 
> 
<LinearLayout 

.. 
android:layout_below="@+id/button" 
>... 

</RelativeLayout> 

更新

你要這樣呢?

enter image description here

+0

無法正常工作,我收到每個項目的按鈕, – user2367219

+0

是的,我想要的是照片中的內容。 – user2367219

+0

看到這裏的鏈接它有完整的教程http://www.vogella.com/articles/AndroidListView/article.html –