gpt4 book ai didi

java - ListView不显示所有项目

转载 作者:太空宇宙 更新时间:2023-11-04 13:12:00 24 4
gpt4 key购买 nike

这个问题看起来很简单,但我现在无法解决这个问题。

我在 ScrollView 中有 ListView (我知道不要这样做)

现在,通过 ScrollView 中的 ListView,我使用自定义 View ExpandableHeightListView ( how to make multiplelistview in Scrollview? ) 来显示所有项目。

这是我的 ScrollView

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:orientation="vertical"
android:id="@+id/layoutHero">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="ANTI-MAGE"
android:id="@+id/txtName"
android:gravity="center_horizontal"
android:textSize="30sp"
android:textStyle="bold"/>

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/item_weapons"
android:id="@+id/imageHero"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Carry - Nuker - Melee - Escape"
android:gravity="center_horizontal"
android:id="@+id/txtRoles"
android:textSize="16sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@id/layoutHero"
android:id="@+id/layoutBio"
android:layout_marginTop="5dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/material_blue_grey_800"></LinearLayout>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BIO"
android:clickable="true"
android:id="@+id/bioTextView"
android:layout_marginTop="5dp"
android:textSize="20dp"
android:gravity="center_horizontal"
android:textColor="#793838"
android:textStyle="bold"/>

<TextView
android:layout_width="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_height="wrap_content"
android:id="@+id/txtBio"
android:text="The monks of Turstarkuri watched kahfksajfhskald"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@id/layoutBio"
android:id="@+id/skillLayout"
android:layout_marginTop="5dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/material_blue_grey_800"></LinearLayout>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="OVERVIEW"
android:layout_marginTop="5dp"
android:id="@+id/overviewLayout"
android:textSize="20dp"
android:gravity="center_horizontal"
android:textColor="#793838"
android:textStyle="bold"/>

<com.dotalibrary.ExpandableHeightListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lstSkill"
android:fadingEdge="none"
android:focusable="false"
android:scrollbars="none"
android:nestedScrollingEnabled="true"
>

</com.dotalibrary.ExpandableHeightListView>
</LinearLayout>
</RelativeLayout>

这是listView的项目

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/layoutLeft" android:orientation="horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:paddingTop="10dp"
android:src="@mipmap/ic_launcher"
android:id="@+id/imageAbility"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mana Break"
android:layout_toLeftOf="@id/imageAbility"
android:id="@+id/txtAbility"
android:textSize="18sp"
/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:id="@+id/txtDetail"
android:text="akjdfhakdfjhakdfjhadfkjhadkfjakdjfhadksjfhdakfjhadkfadfkjhadklfhafkldahfkasfh"/>


</LinearLayout>
</LinearLayout>




<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="NOTE: blah blahsalkfdjdlkj"
android:id="@+id/txtAbilityNote"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtAffect"
android:text="A modified technique of the Turstarkuri monks"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtAttribs"
android:text="A modified technique of the Turstarkuri monks"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtDamage"
android:text="A modified technique of the Turstarkuri monks"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtCmb"
android:text="A modified technique of the Turstarkuri monks"/>

</LinearLayout>

这是自定义类实现ListView

 public class ExpandableHeightListView extends ListView{

boolean expanded = false;

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

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

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

public boolean isExpanded()
{
return expanded;
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
// HACK! TAKE THAT ANDROID!
if (isExpanded())
{
// Calculate entire height by providing a very large height hint.
// But do not use the highest 2 bits of this integer; those are
// reserved for the MeasureSpec mode.
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, 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;
}
}

现在,当我通过Adapter将数据设置到ListView时。 ListView 不显示我设置的所有项目。例如:我设置了4个项目,它只显示3或3.5个项目

谁能给我一些建议?

谢谢。

最佳答案

您需要创建一个java自定义ScrollView类并在您的xml中使用它而不是原始的ScrollView。您可以在此处找到 VerticalScrollview 类代码: https://stackoverflow.com/a/13796159/3376613

关于java - ListView不显示所有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33867708/

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