2017-09-16 40 views
0

之间的区别我有下面的网格布局Xamarin的ListView:构造器和模拟器

<?xml version="1.0" encoding="utf-8"?> 
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:minWidth="25px" 
    android:minHeight="25px" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:columnCount="1" 
    android:rowCount="5"> 
    <ListView 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_rowWeight="0.7" 
     android:layout_width="match_parent" /> 
    <TextView 
     android:text="Введите показания водомера" 
     android:textSize="24dp" 
     android:layout_rowWeight="0.05" 
     android:layout_width="match_parent" 
     android:gravity="center"/> 
    <EditText 
     android:inputType="number" 
     android:layout_rowWeight="0.03" 
     android:layout_width="match_parent" /> 
    <Button 
     android:text="Сделать фото" 
     android:textSize="20dp" 
     android:layout_rowWeight="0.05" 
     android:layout_width="match_parent" 
     android:gravity="center" /> 
    <Button 
     android:text="Отправить показания" 
     android:textSize="24dp" 
     android:layout_rowWeight="0.15" 
     android:layout_width="match_parent" 
     android:gravity="center" /> 
</GridLayout> 

在VS构造看起来像 this。 但在模拟器中,我得到this。 如何在第一张图片上设置ListView的高度?

+0

为什么使用'GridLayout'有特殊原因吗?使用硬编码的“宽度”和“高度”,你将很难达到你想要的。为什么不使用'LinearLayout'作为一个垂直方向的容器,并在2'LinearLayouts'中加上2和1的权重。我将一个'ListView'放在代码的第二个剩余部分。 – Yupi

+0

@Yupi'GridLayout'允许我调整不同设备上的控件大小 – NisuSan

回答

0

我发现了一种方法来解决这个问题,方法是从nuget向我的项目中添加一个自定义的android.support.v7并在xml中使用其模式。

<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:minWidth="25px" 
    android:minHeight="25px" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:columnCount="1" 
    app:rowCount="5"> 
</android.support.v7.widget.GridLayout>