2015-11-23 4 views
1

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

У меня есть ListView в ScrollView (я знаю, что не делаю этого)

Теперь, с ListView в ScrollView Я с помощью пользовательского просмотра 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

Вы когда-нибудь изменяли переменную 'extended' в' true'? – Titus

+0

Самый простой способ справиться с этим - отказаться от lisview и заменить его линейной компоновкой, что-то вроде этого http://stackoverflow.com/questions/28634232/set-adapter-to-linearlayout-instead-of-listview – AbuQauod

+0

@Titus Я уже установил lstSkill.setExpanded (true) в действии –

ответ

0

Вам необходимо создать собственный класс ScrollView java и использовать его в своем xml вместо исходного ScrollView. Код типа VerticalScrollview можно найти здесь: https://stackoverflow.com/a/13796159/3376613

Смежные вопросы