2014-07-20 3 views
0

내 ListView가 현재 내 화면의 작은 작은보기 상자에 고정되어 있습니다. 클릭하면 높이로 확장하고 싶습니다. 나는 그것을하는 방법에 대한 가이드를 읽었지만 아무것도 작동하지 않는 것 같습니다. 여기에 제 코드가 있습니다.ListView의 높이 설정 onClick

list.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      Log.v("Miles", "Listview clicked"); 
      LayoutParams adapterParams = (LayoutParams) parent.getLayoutParams(); 
      adapterParams.height = 400; 
      parent.setLayoutParams(adapterParams); 
     } 
    }); 

그리고이 코드 조각에서 일어나는 레이아웃 : 어떤 이유

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="tribeTimes.EventFragment" 
android:focusable="true" 
android:focusableInTouchMode="true" > 

<TextView 
    android:id="@+id/event" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

    <TextView 
     android:background="@drawable/buttonborder_selector" 
     android:id="@+id/likes" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/event" 
     android:layout_marginBottom="20dp" 
     android:clickable="true" 
     android:gravity="center" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <EditText 
     android:background="@drawable/buttonborder_selector" 
     android:hint="@string/yourComment" 
     android:id="@+id/yourComment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/likes" 
     android:layout_marginBottom="20dp" 
     android:gravity="left" 
     android:inputType="text" > 
     <requestFocus/> 
    </EditText> 

    <ListView 
     android:layout_below="@id/yourComment" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/listInParent" > 
    </ListView> 

</RelativeLayout> 

답변

1

귀하의 ListView은 "작은 작은보기 상자에 고정되어 있습니다"이며 높이를 wrap_content으로 설정 했으므로 그 안에 몇 개의 항목 만 있거나 잘 지내지 못했습니다. 높이를 다른 방법으로 설정하십시오. 따라서 예를 들어 으로 ListView의 초기 높이를 설정했습니다. 나는 당신이 어떤 것을 조정할 필요가있을 것이라고 확신한다. ListView 크기를 조정하면

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="tribeTimes.EventFragment" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:focusable="true" 
    android:focusableInTouchMode="true" > 

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

     <TextView 
      android:id="@+id/event" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <TextView  
      android:id="@+id/likes" 
      android:background="@drawable/buttonborder_selector" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dp" 
      android:clickable="true" 
      android:gravity="center" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <EditText 
      android:id="@+id/yourComment" 
      android:background="@drawable/buttonborder_selector" 
      android:hint="@string/yourComment" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dp" 
      android:gravity="left" 
      android:inputType="text" > 
      <requestFocus/> 
     </EditText> 

    </LinearLayout> 

    <ListView 
     android:layout_width="wrap_content" 
     android:layout_height="100dp" 
     android:layout_alignParentBottom="true" 
     android:id="@+id/listInParent" > 
    </ListView> 

</RelativeLayout> 

그런 다음, 당신이 그들을 설정하기 전에 매개 변수에 레이아웃 규칙을 추가해야합니다.

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(list.getWidth(), 400); 
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
list.setLayoutParams(lp); 
0

list.setLayoutParams(new RelativeLayout.LayoutParams(400, 600))리스트 뷰 자체의 높이를 변경했다. 이제 문제는 다른 뷰가 그에 따라 크기가 조정되지 않는다는 것입니다. 에서처럼 목록보기가 커지면 접기도하지 않습니다.