관리 메뉴

막내의 막무가내 프로그래밍 & 일상

[안드로이드] FrameLayout, ScrollView 사용시 특정 뷰 위치 고정시키기 본문

안드로이드

[안드로이드] FrameLayout, ScrollView 사용시 특정 뷰 위치 고정시키기

막무가내막내 2020. 1. 18. 17:14
728x90

 

 

* 프로그래머스 화해 과제인데 작성날짜는 비공개로 올린 날짜고 공개로 돌린 건 과제가 종료되고 한달뒤쯤임을 말씀드립니다.

 

그냥 FrameLayout과 ScrollView를 동시에 사용시 스크롤뷰를 내리면 프레임레이아웃으로 설정해논 버튼이 사라진다.

 

viewPort등 다양한 방법을 봤지만 난 다음과 같이 해결하였다.

 

LinearLayout이 가장 상위 레이아웃으로 두고

그 밑에 프레임레이아웃을 두고 

프레임레이아웃 자식으로 스크롤뷰와(스크롤이 될 뷰) 고정되야할 뷰를 두었다.

 

<?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:orientation="vertical"
    android:layout_height="match_parent"
    android:paddingTop="8dp"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingBottom="24dp"
    tools:context=".activities.PurchaseActivity">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/purchase_iv_image"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:padding="8dp"
            tools:src="@tools:sample/avatars" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/colorLightGray"/>
        <TextView
            android:id="@+id/purchase_tv_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:textSize="36sp"
            android:text="국제약 센틸리안24 파워 부스팅 포뮬러 마데카 크림 50ml "
            android:textStyle="bold" />
        <TextView
            android:id="@+id/purchase_tv_price"
            android:padding="16dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:textSize="28sp"
            android:textColor="@color/colorPurple"
            android:text="10,800원" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/colorLightGray"/>

        <TextView
            android:id="@+id/purchase_tv_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:textSize="20sp"
            android:text="@string/ex_sentence"/>
        <TextView
            android:padding="16dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="15sp"
            android:background="@drawable/bg_round_gray"
            android:textColor="@color/colorGray"
            android:layout_marginBottom="60dp"
            android:text="@string/notice"
            />
    </LinearLayout>
    </ScrollView>
        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/purchase_civ_close"
            android:layout_width="40dp"
            android:src="@drawable/ic_close"
            android:layout_gravity="end|top"
            android:layout_marginEnd="16dp"
            android:layout_marginTop="16dp"
            android:layout_height="40dp" />
    <Button
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:id="@+id/purchase_btn_purchase"
        android:padding="16dp"
        android:layout_width="match_parent"
        android:layout_gravity="bottom|center_horizontal"
        android:text="구매하기"
        android:background="@drawable/bg_round_purple"
        android:textColor="@color/colorWhite"
        android:layout_marginBottom="16dp"
        android:layout_height="wrap_content"/>
</FrameLayout>
</LinearLayout>

 

 

 

728x90
Comments