按钮覆盖列表视图项目和如何添加textview上面的列表视图



我在标题和按钮之间有一个列表视图,我想在列表视图和按钮上方添加textview以正确对齐,以便按钮不覆盖列表视图项。我怎么能做到呢?不知道xml布局有什么问题

layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#e7ebee"
    android:gravity="center"
    android:orientation="vertical"
    android:weightSum="1">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="452dp"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >
        <RelativeLayout
            android:id="@+id/mainheader"
            android:layout_width="fill_parent"
            android:layout_height="52dp"
            android:background="#0a2436">
            <RelativeLayout
                android:id="@+id/subheader"
                android:layout_width="wrap_content"
                android:layout_height="52dp" >
                <ImageView
                    android:id="@+id/back"
                    android:layout_width="40dip"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_centerVertical="true"
                    android:background="@drawable/my_highlight_drawable"
                    android:src="@drawable/back" />
                <ImageView
                    android:id="@+id/inboxheader"
                    android:layout_width="2dip"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginRight="5dp"
                    android:layout_toRightOf="@+id/back"
                    android:background="#85929B"
                    android:paddingBottom="15dip"
                    android:paddingTop="15dip" />
            </RelativeLayout>
            <ImageView
                android:id="@+id/windowtitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:contentDescription="@null"
                android:src="@drawable/logo" />
        </RelativeLayout>
        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:divider="@android:color/darker_gray"
            android:dividerHeight="1dip"
            android:drawSelectorOnTop="false"
            android:focusable="false"
            android:paddingTop="0dip" />
        <TextView
            android:id="@+id/android:empty"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:text="No Data Available"
            android:visibility="invisible" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >
        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_centerInParent="true"
            android:gravity="bottom">
            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#092435"
                android:gravity="center_horizontal" >
                <Button
                    android:id="@+id/btnManualLookup"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:background="#4982AE"
                    android:gravity="center"
                    android:padding="15dip"
                    android:text="Submit"
                    android:textColor="#ffffff" />

            </TableRow>
        </TableLayout>
    </LinearLayout>
</LinearLayout>

是否考虑过在listview中添加headerview ?你可以使用布局作为listview的header。这样,你的header上的视图就不会溢出到listview上。

final ListView lstVRHDetails = (ListView) getActivity().findViewById(R.id.listview);
        LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View headerView = inflater.inflate(<header layout>, new LinearLayout(getActivity()), false);
        headerView.findViewById(R.id.rlFromDate).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
            }
        });
        headerView.findViewById(R.id.rlToDate).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
            }
        });
        headerView.findViewById(R.id.imgUpdate).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        headerView.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, ListView.LayoutParams.WRAP_CONTENT));
        lstVRHDetails.addHeaderView(headerView);

最新更新