Последняя строка расширяемого списка не полностью отображается в Android

Вид строки с красной меткой

Здесь я использую представление и код, как указано ниже.

 <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:orientation="vertical">

                            <TableRow
                                android:id="@+id/tab_stone_info"
                                android:layout_width="match_parent"
                                android:layout_height="30dp"
                                android:layout_marginTop="1dp"
                                android:background="@color/styleBreakTabColor"
                                android:weightSum="9">

                                <TextView
                                    android:id="@+id/stone_Type"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:background="@drawable/cell_shape"
                                    android:gravity="center"
                                    android:text="@string/Type"
                                    android:textColor="@color/txtStyleBreakup"
                                    android:textSize="12sp" />

                                <TextView
                                    android:id="@+id/stone_Shape"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:background="@drawable/cell_shape"
                                    android:gravity="center"
                                    android:text="@string/Shape"
                                    android:textColor="@color/txtStyleBreakup"
                                    android:textSize="12sp" />

                                <TextView
                                    android:id="@+id/stone_Qlty"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:background="@drawable/cell_shape"
                                    android:gravity="center"
                                    android:text="@string/Quality"
                                    android:textColor="@color/txtStyleBreakup"
                                    android:textSize="12sp" />

                                <TextView
                                    android:id="@+id/stone_Grade"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:background="@drawable/cell_shape"
                                    android:gravity="center"
                                    android:text="@string/Grade"
                                    android:textColor="@color/txtStyleBreakup"
                                    android:textSize="12sp" />

                                <TextView
                                    android:id="@+id/stone_Qty"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:background="@drawable/cell_shape"
                                    android:gravity="center"
                                    android:text="@string/Qty"
                                    android:textColor="@color/txtStyleBreakup"
                                    android:textSize="12sp" />

                                <TextView
                                    android:id="@+id/stone_Wt"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:background="@drawable/cell_shape"
                                    android:gravity="center"
                                    android:text="@string/Wt"
                                    android:textColor="@color/txtStyleBreakup"
                                    android:textSize="12sp" />

                                <TextView
                                    android:id="@+id/stone_MMSize"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:background="@drawable/cell_shape"
                                    android:gravity="center"
                                    android:text="@string/MMSize"
                                    android:textColor="@color/txtStyleBreakup"
                                    android:textSize="12sp" />

                                <TextView
                                    android:id="@+id/stone_Setting"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:background="@drawable/cell_shape"
                                    android:gravity="center"
                                    android:text="@string/Setting"
                                    android:textColor="@color/txtStyleBreakup"
                                    android:textSize="12sp" />

                                <TextView
                                    android:id="@+id/stone_SettMode"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:background="@drawable/cell_shape"
                                    android:gravity="center"
                                    android:text="@string/SettingMode"
                                    android:textColor="@color/txtStyleBreakup"
                                    android:textSize="12sp" />

                            </TableRow>

                            <RelativeLayout
                                android:id="@+id/layout_tab_stone_info_value"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"

                               >

                                <com.mindtech.ExpandableHeightListView
                                    android:id="@+id/listviewstone"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:divider="#00000000"
                                    android:gravity="center"
                                    android:horizontalSpacing="2dp"
                                    android:isScrollContainer="false"
                                    android:stretchMode="columnWidth"
                                    android:verticalSpacing="20dp"
                                     />
                            </RelativeLayout>
                        </LinearLayout>

И я использую epandablelistview как класс ниже.

public class ExpandableHeightListView extends ListView
{

    boolean expanded = false;

    public ExpandableHeightListView(Context context, AttributeSet attrs,
                                    int defStyle)
    {
        super(context, attrs, defStyle);
    }

    public ExpandableHeightListView(Context context)
    {
        super(context);
    }

    public ExpandableHeightListView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }



    public boolean isExpanded()
    {
        return expanded;
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {

//        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
//                MeasureSpec.AT_MOST);

//
//        super.onMeasure(widthMeasureSpec, expandSpec);


//        int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
//                Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
//        ViewGroup.LayoutParams params = getLayoutParams();
//        params.height = getMeasuredHeight();


        if (isExpanded())
        {

            int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
                    MeasureSpec.AT_MOST);
            super.onMeasure(widthMeasureSpec, expandSpec);

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = getMeasuredHeight();
        }
        else
        {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }

    public void setExpanded(boolean expanded)
    {
        this.expanded = expanded;
    }
}

Я передаю этот вопрос, но не получил правильного ответа. Сетка изображений внутри ScrollView

Высота Gridview уменьшается

Основная проблема возникает, когда высота первой строки не больше второй или другой. если длина всего содержимого строки одинакова, проблем нет.


person Ramchandra Singh    schedule 07.04.2017    source источник
comment
показать содержимое списка, удерживать xml   -  person IntelliJ Amiya    schedule 07.04.2017
comment
пожалуйста, проверьте, что я добавил xml @IntelliJAmiya   -  person Ramchandra Singh    schedule 07.04.2017
comment
Покажите полный xml пожалуйста   -  person IntelliJ Amiya    schedule 07.04.2017
comment
слишком много представления, которое не может отображаться здесь .. проблемы только в расширяемом списке и классе расширяемого списка   -  person Ramchandra Singh    schedule 07.04.2017
comment
проверьте наличие отступов снизу или полей снизу.   -  person IntelliJ Amiya    schedule 07.04.2017
comment
нет, это не проблемы с полями или заполнением. Проблемы с высотой этой строки int expandSpec = MeasureSpec.makeMeasureSpec (MEASURED_SIZE_MASK, MeasureSpec.AT_MOST); super.onMeasure (widthMeasureSpec, expandSpec); ViewGroup.LayoutParams params = getLayoutParams (); params.height = getMeasuredHeight ();   -  person Ramchandra Singh    schedule 07.04.2017
comment
это может помочь вам stackoverflow.com/a/8406253/3758898   -  person Kishan Vaghela    schedule 10.04.2017


Ответы (3)


Похоже, вы получаете LayoutParams для своего ListView, изменяя параметр высоты, но вы никогда не вызываете setLayoutParams, чтобы указать представлению использовать измененную высоту. Попробуй это:

if (isExpanded()) {

    int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
            MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, expandSpec);

    ViewGroup.LayoutParams params = getLayoutParams();
    params.height = getMeasuredHeight();
//Add this line
    setLayoutParams(params);
}

Кроме того, в прошлом я сталкивался с проблемами с методом onMeasure (), не все измеряется, когда фреймворк вызывает этот метод. Вы можете попробовать ViewTreeObserver, где вы можете зарегистрировать слушателя, который будет уведомляется, когда выкладывается полный вид, например:

final LinearLayout layout = (LinearLayout) findViewById(R.id.layout_id);
ViewTreeObserver vto;
if (layout != null) {
    vto = layout.getViewTreeObserver();

    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            layout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            //Modify your LayoutParams here
        }
    });
}
person Jason Powell    schedule 12.04.2017

Если есть только один дочерний элемент, то лучше использовать ExpandableListView или RecyclerView с разными layouts. Здесь полное и очень хорошее руководство по используя ExpandableListView.

При использовании ListView он всегда добавляет высоту, которая немного меньше исходной (или, может быть, есть другой случай, но я не знаю почему. Если кто-то знает, то любезно поправьте меня). Поэтому вам нужно вручную добавить dp's высоты в конце.

Я сделал это, переопределив метод onDraw. Ниже я расскажу, как я это сделал.

@Override
protected void onDraw(Canvas canvas) {
    params = getLayoutParams();
    if (getCount() != old_count) {
        old_count = getCount();
        params.height = getCount() * (old_count > 0 ? getChildAt(0).getHeight()+5 : 0);
        //I've added 5 pixels with each item to get proper height, you can alter it as per your need
        setLayoutParams(params);
    }
    super.onDraw(canvas);
}
person Waqas Ahmed Ansari    schedule 12.04.2017

Вы изменяете высоту, но не передаете ее представлению.

Используйте этот метод setLayoutParams (params);

person Raj    schedule 16.04.2017