Search code examples
androidlistviewxamarinadapterandroid-relativelayout

Ralative Layout inside ListView


I've the following Relativelayout, which contains Linearlayout with Labels. This Relativelayout pushed to the custom ListView in custom adapter. I expected to see Relativelayouts one by one, but got this

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:minWidth="25px"
    android:minHeight="25px"
    android:padding="8sp">
  <LinearLayout
      android:orientation="vertical"
      android:minWidth="25px"
      android:minHeight="25px"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
    <TextView
        android:text="Водомер 1"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="4sp"
        android:layout_toRightOf="@id/linearLayout1"
    <TextView
        android:text="Последняя поверка:"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/linearLayout1"
    <TextView
        android:text="Последние показания:"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/linearLayout1"
    <TextView
        android:text="Текущие показания:"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/linearLayout1"
  </LinearLayout>
  <ImageView
      android:src="@android:drawable/ic_menu_gallery"
      android:layout_width="76sp"
      android:layout_height="76sp"
      android:paddingRight="13sp"
      android:layout_alignParentRight="true"
</RelativeLayout>

Target layout seems like this. And if I set to this ListView any other custom view, it looks fine.

<?xml version="1.0" encoding="utf-8"?>
<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="7">
    <TextView
        android:text="Список водомеров"
        android:layout_width="match_parent"
        app:layout_rowWeight="0.05"
        android:gravity="center_horizontal"/>
    <ListView
        android:minWidth="25px"
        android:minHeight="25px"
        app:layout_rowWeight="0.3"
        android:layout_width="match_parent"
        android:choiceMode="singleChoice" />
    <TextView
        android:text="Введите показания водомера"
        app:layout_rowWeight="0.02"
        android:layout_width="match_parent"
        android:gravity="center" />
    <EditText
        android:inputType="number"
        app:layout_rowWeight="0.04"
        android:layout_width="match_parent"/>
    <Button
        android:text="Сделать фото"
        android:textSize="20dp"
        app:layout_rowWeight="0.02"
        android:layout_width="match_parent"
        android:gravity="center"/>
    <Button
        android:text="Отправить показания"
        android:textSize="24dp"
        app:layout_rowWeight="0.15"
        android:layout_width="match_parent"
        android:gravity="center"/>
    <Space
        app:layout_rowWeight="0.3" />
</android.support.v7.widget.GridLayout>

How I can fix this?


Solution

  • For resolve my problem I used advice of LQ Gioan and replace target GridLayout to LinearLayout with weightSum property. In the content elements I'm using layout_weight property.

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="100">
    <TextView
            android:text="Список водомеров"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:layout_weight="11"
            android:id="@+id/textView1" />