마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

listview 높이 조절 에따른 문제

0 추천
동적으로 리스트에 아이템을 추가하고있는데요 리스트뷰 밑에 버튼을 넣을경우 아이탬이 적을 경우는 상관없는데 아이템이 많아지면 버튼이 사라집니다.

엑티비티는 다이얼로그 형식으로 만들었는데 동적으로 추가되다가 일정 아이템이상이들어오면 스크롤되도록 변경 하는 방법이 있나요??
루운 (1,160 포인트) 님이 2014년 2월 25일 질문

2개의 답변

0 추천
 
채택된 답변
이렇게 하시면 될것같습니다~

<LinearLayout

......

android:orientation="vertical"

>

     <ListView

      ...........

      android:layout_height="0dp"

      android:weight="1"

      />

     <Button

     ..............

      />

</LinearLayout>
주드로 (590 포인트) 님이 2014년 2월 25일 답변
루운님이 2014년 3월 3일 채택됨
똑같이해봤는데 일정 이상 아이템이 늘어나면 버튼이 사라지네요 ㅠㅠ 왜이러지..
작성하신 xml코드를 볼 수 있나요?
보여주시면 수정해드릴게요~
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/background_color"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/root_ra01"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/liner01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/category_title"
            android:orientation="horizontal" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="15dp"
                android:layout_marginTop="5dp"
                android:text="@string/app_name"
                android:textColor="@android:color/white"
                android:textSize="20dp" />
        </LinearLayout>

        <RelativeLayout
            android:id="@+id/liner02"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/liner01"
            android:minHeight="45dp" >

            <TextView
                android:id="@+id/title_devices"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:paddingLeft="12dp"
                android:paddingRight="50dp"
                android:text="@string/select_device"
                android:textColor="@android:color/holo_blue_light"
                android:textSize="20dip" />

            <ImageView
                android:id="@+id/about"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:src="@android:drawable/ic_menu_info_details" />
        </RelativeLayout>
    </RelativeLayout>

    <TextView
        android:id="@+id/empty"
        android:layout_width="wrap_content"
        android:layout_below="@id/root_ra01"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:minHeight="60dp"
        android:padding="10dp"
        android:text="@string/scanning" />

    <RelativeLayout
        android:id="@+id/liner03"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/empty"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/linearLayout01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >

            <ListView
                android:id="@+id/new_devices"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:stackFromBottom="true" />
        </LinearLayout>


             <LinearLayout
            android:id="@+id/root_ra02"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/linearLayout01"
            android:background="@drawable/button_bg"
            android:gravity="center" >

            <Button
                android:id="@+id/btn_cancel"
                style="?android:attr/buttonBarButtonStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/button_cancel" />
        </LinearLayout>
  
    </RelativeLayout>

</RelativeLayout>
이런식으로 되어 있습니다
liner03 레이아웃이 RelativeLayout이네요. 저걸 LinearLayout으로 바꿔주시면 됩니다.
답변을 빨리 해드려야하는데 늦었네요 ㄷㄷ
0 추천
리스트뷰의 영역을 초과하면 스크롤이 자동으로 생성될텐데요.

리스트뷰의 아래에 버튼을 넣고 싶으시면

Main 레이아웃에서 리스트뷰의 Height 속성을 줄이고 (dp로 지정) 그 밑에 버튼을 넣으세요
초보개발자ㅠ (33,870 포인트) 님이 2014년 2월 25일 답변
동적으로 할당할수 있는방법을 생각중이라서요 ㅠ 답변 감사합니다
...