我有一个页面要在其中放置表格,并在上方和下方有按钮。我的布局具有以下XML。但是,即使我能解决,也行不通!

编辑:我已经更新了XML以显示我想要实现的目标。里面的表,但是它不允许我通过ListView listView = (ListView) findViewById(R.id.lvLocation);访问



    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/btnAdd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Add Item" />

       <ListView
           android:id="@+id/lvLocation"
           android:layout_width="match_parent"
           android:layout_height="fill_parent"
           android:layout_above="@+id/btnBack"
           android:layout_alignParentLeft="true"
           android:layout_below="@+id/btnAdd"
           android:drawSelectorOnTop="false" >

    </ListView>

    <Button
        android:id="@+id/btnBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="Back" />

</RelativeLayout>


我的代码:(删除了Db调用和数组设置)

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_location_list_view);


    ListView listView = (ListView) findViewById(R.id.lvLocation);
    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
          android.R.layout.simple_list_item_2, android.R.id.text1, mArrayList);

    int[] colors = {0, 0xFFFF0000, 0};
    listView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
    listView.setDividerHeight(1);
    listView.setAdapter(adapter);

    }



}


这是我想要达到的目标。不是颜色,只是概念:

最佳答案

我认为这会有所帮助

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/btnAdd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Add Item" />

    <TableLayout
        android:id="@+id/lvLocation"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/btnBack"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/btnAdd" >

    </TableLayout>

    <Button
        android:id="@+id/btnBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="Back" />

</RelativeLayout>

07-24 09:49
查看更多