2017-09-16 38 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>