这个问题看似简单但我现在无法解决这个问题。
我在ScrollView中有ListView(我知道不要这样做)
现在,使用ScrollView中的ListView,我使用自定义视图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;
}
}
现在,当我通过适配器将数据设置为ListView时。 ListView不显示我设置的所有项目。示例:我设置了4项,它只显示3或3.5项
谁可以给我建议呢?
谢谢。
答案 0 :(得分:0)
您需要创建一个java自定义ScrollView类,并在xml而不是原始ScrollView中使用它。 您可以在此处找到VerticalScrollview类代码: https://stackoverflow.com/a/13796159/3376613