ListActivity标头使用与行相同的格式

时间:2013-03-26 17:22:54

标签: java android

我想在ListActivity的列表视图上方添加一个标题栏。滚动列表视图时,标题栏不应滚动,因此我不使用addHeaderView(),而是使用XML定义的自定义视图。它看起来像这样:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
        android:paddingLeft="8dp"
        android:paddingRight="8dp">       
    <LinearLayout
            android:id="@+id/top_control_bar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:orientation="vertical"> 
        <RelativeLayout 
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"             
                android:orientation="vertical">
                <TextView android:id="@+id/left_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:text="Some text" />
            <ImageView
                    android:id="@+id/imageView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentRight="true"
                android:src="@drawable/ic_launcher" />
        </RelativeLayout>           
    </LinearLayout>
    <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
        android:layout_height="match_parent"
            android:layout_weight="1" 
                android:layout_below="@id/top_control_bar"          
        android:drawSelectorOnTop="false" />
</RelativeLayout> 

如您所见,标题栏包含文本视图和图像视图。我现在的问题是:我希望这个标题栏使用与列表视图中的单行完全相同的大小(标题栏高度和字体大小)。我不想硬编码任何大小的信息。相反,标题栏应该总是与我的listview中的单行一样大,Android也应该从我的标题栏中的图像视图中选择适当大小的“ic_launcher”可绘制的ic_launcher的不同大小的一组* .apk但我认为这是自动完成的。我只需要找到一种方法来告诉标题栏始终与列表视图中的单行一样大,标题栏文本视图的字体大小也应该与列表视图行的字体大小相匹配。 / p>

任何人都可以告诉我如何实现这一目标吗?非常感谢!

0 个答案:

没有答案
相关问题