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

레이아웃 질문입니다. listview 바로하단에 button이 나왔으면합니다.

0 추천
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".ui.home.HomeFragment">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:fillViewport="true">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <ListView
                android:id="@+id/listView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            </ListView>
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="ADD"/>
        </LinearLayout>
    </ScrollView>
</LinearLayout>
listview 바로밑 버튼이 listview밑에 나오는게아니고 화면 상단으로 자꾸갑니다. listview 밑에 바로나오게할수없나요?
ellrewa (240 포인트) 님이 2023년 5월 25일 질문

2개의 답변

0 추천

ScrollView는 최상위 레이아웃이 되는게 맞을 것 같구요. 버튼을 같이 스크롤 하고 싶으신거면 ScrollView대신에 NestedScrollView를 사용하셔야 할 것 같은데, 100% 정확하게 기억이 안나니 테스트 해보세요.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    tools:context=".ui.home.HomeFragment">

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

        <ListView
            android:id="@+id/listView"
            tools:listitem="@android:layout/simple_list_item_2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="ADD" />
    </LinearLayout>
</ScrollView>

 

ListView는 성능상의 이유와 라이브러리 지원 등의 이유로 요즘 사용하는 사람이 거의 없으므로 RecyclerView를 검토해 보시기 바랍니다.

spark (224,800 포인트) 님이 2023년 5월 25일 답변
0 추천
ListView 와 Button 을 감싸고있는 LinearLayout 에 orientation 속성이 빠져서 그런것은 아닐까요
익명 님이 2023년 5월 30일 답변
...