gpt4 book ai didi

android - 最后一行可扩展 ListView 在 android 中不是完整 View

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:00 24 4
gpt4 key购买 nike

Red mark Row view

这里我使用 View ,那里的代码如下所示。

 <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;
}
}

我提到了这个问题,但没有得到正确的答案。 Grid of images inside ScrollView

Gridview height gets cut

主要问题发生在第一行高度不大于第二行或其他行高时。如果所有行内容长度都相同,则没有问题。

最佳答案

看起来您正在获取 ListView 的 LayoutParams,修改高度参数,但您从未调用 setLayoutParams 来告诉 View 使用修改后的高度。试试这个:

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 ,您可以在其中注册一个监听器,以便在布局完整 View 时收到通知,如下所示:

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
}
});
}

关于android - 最后一行可扩展 ListView 在 android 中不是完整 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43276622/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com