在Xamarin / Android中创建ListView菜单的问题

时间:2017-11-12 15:41:24

标签: android listview xamarin

我在Xamarin中创建一个简单的链接菜单时遇到了麻烦。所需的布局是图像标题,链接列表和底部的按钮以关闭菜单。我使用ListView来显示链接。

我的布局在Visual Studio Designer中根据需要显示,但是当在模拟器或实际的Android设备上运行时,ListView会占用整个屏幕,页眉和页脚也不可见。我已经尝试了我能想到的一切,包括几种不同的布局,并且总是得到相同的结果。

我的XAML在下面。帮助

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayout1">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/topLayout">
    <Toolbar
        android:minHeight="?android:attr/actionBarSize"
        android:background="?android:attr/colorPrimary"
        android:minWidth="25px"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/toolbar1">
        <ImageView
            android:src="@drawable/logo1"
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="1.0dp"
            android:layout_gravity="center" />
    </Toolbar>
</LinearLayout>
<ListView
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:id="@+id/android.r."
    android:background="#ffffffff" />
<LinearLayout
    android:orientation="vertical"
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/linearLayout2">
    <Toolbar
        android:minHeight="?android:attr/actionBarSize"
        android:background="#ffff8902"
        android:minWidth="25px"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:id="@+id/toolbar3"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="0.0dp">
        <Button
            android:text="^"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/menuCloser"
            android:layout_gravity="center"
            android:layout_marginLeft="0.0dp"
            android:layout_marginRight="0.0dp"
            android:textSize="40dp"
            android:background="?android:attr/selectableItemBackground"
            android:ems="1"
            android:onClick="OnCloseMenu"
            android:shadowColor="@android:color/transparent"
            android:textColor="#ffffffff" />
    </Toolbar>
</LinearLayout>
</LinearLayout>

2 个答案:

答案 0 :(得分:0)

如果您有更多项目,则在列表中,您必须滚动才能到底部查看页脚。 Visual Studio设计器将向您显示包含较少项目的示例列表,以便您可以查看页眉和页脚。如果你想将页脚放在一个固定的,即你不想滚动,那么使用相对布局。

答案 1 :(得分:0)

只需用

替换listview代码即可
<ListView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/android.r."
        android:background="#ffffffff" />

1&GT;如果您使用体重,则问题出现在您的android:layout_height="0dp" 0dp

2 - ;我的建议是使用RecyclerView的android,因为你会在ListView

中遇到许多不一致

3&GT;你的代码需要清理,因为我认为你是android的新手

所以建议我刚刚删除了一些未使用的属性,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/linearLayout1">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/topLayout">
        <Toolbar
            android:background="?android:attr/colorPrimary"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:id="@+id/toolbar1">
            <ImageView
                android:src="@drawable/ic_back"
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                />
        </Toolbar>
    </LinearLayout>
    <ListView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/android.r."
        android:background="#ffffffff" />
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayout2">
        <Toolbar
            android:minHeight="?android:attr/actionBarSize"
            android:background="#ffff8902"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/toolbar3"
            >
            <Button
                android:text="^"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/menuCloser"
                android:layout_gravity="center"
                android:layout_marginLeft="0.0dp"
                android:layout_marginRight="0.0dp"
                android:textSize="40dp"
                android:background="?android:attr/selectableItemBackground"
                android:ems="1"
                android:onClick="OnCloseMenu"
                android:shadowColor="@android:color/transparent"
                android:textColor="#ffffffff" />
        </Toolbar>
    </LinearLayout>
</LinearLayout>