无法通过ListActivity查看我的页脚

时间:2013-03-15 17:13:32

标签: android android-layout footer

我正在尝试为我的自定义列表做页脚但仍无法解决问题。 我的目的只是在列表末尾添加一些按钮。 我试过这个:

adapter = new GeneralRssAdapter(this,R.layout.titlesrss, data);
    LayoutInflater inflater = getLayoutInflater();
    lv.addFooterView( inflater.inflate( R.layout.footer_layout, null ), null, false);
    lv.setAdapter(adapter);

但仍然无法看到任何页脚。 继承人我的xml:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
  <LinearLayout
        android:id="@+id/linearLa"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/iconremove"
            android:layout_width="50dip"
            android:layout_height="50dip"
            android:layout_margin="5dip"
            android:scaleType="centerCrop"
            android:src="@drawable/delete"
            android:visibility="gone" />

        <ImageView
            android:id="@+id/iconfav"
            android:layout_width="50dip"
            android:layout_height="50dip"
            android:layout_margin="5dip"
            android:scaleType="centerCrop"
            android:src="@drawable/rss" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal|center"
            android:layout_margin="5dip"
            android:layout_weight="1"
            android:textSize="20dip" />

    </LinearLayout>
  <ListView android:id="@+id/ListView01"
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"/>

     </RelativeLayout>

和页脚:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

        <ImageView
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1.20"
            android:src="@drawable/tutorialrss"
      />

</LinearLayout>
希望你能帮助我:)。

2 个答案:

答案 0 :(得分:1)

试试这个

 adapter = new GeneralRssAdapter(this,R.layout.titlesrss, data);
         LayoutInflater mInflater = (LayoutInflater)getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    final View footer = mInflater.inflate(R.layout.footer_layout, null);
choicelist.addFooterView(footer);
    choicelist.setAdapter(adapter);

我编辑了这个xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

        <ImageView
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/tutorialrss"
      />

</LinearLayout>

对我来说,它的工作plz检查一次。

enter image description here

adapter = new ListAdapter(this, data);
        ListView lvMain = (ListView) findViewById(R.id.list);
        LayoutInflater mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        final View footer = mInflater.inflate(R.layout.footer, null);
        lvMain.addFooterView(footer);
        lvMain.setAdapter(adapter);

答案 1 :(得分:0)

我所做的是在setContentView()中设置我的页脚/标题,然后在适配器中使用list xml。我通常不喜欢一行答案,但这就是我所做的一切

相关问题