본문 바로가기
프로그래밍/Kotlin

View의 Visible, Gone, invisible 차이

by Youngs_ 2022. 2. 9.

 

binding.frame.visibility = View.VISIBLE // 보이며, 공간도 차지
binding.frame.visibility = View.GONE // 보이지않으며, 공간도 차지하지않음
binding.frame.visibility = View.INVISIBLE // 보이지않지만, 공간은 차지

아래와같은 코드에서 frame layout에 배경색을 지정하면 View.GONE을 하더라도 색이남는다.

고로 LinearLayout에 색을 지정하고 frame을 GONE 해주자

<FrameLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/customLayout_Title"
        tools:ignore="MissingConstraints">
        
        <LinearLayout
            android:id="@+id/linear"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="@color/colorBackgroud"
            android:padding="1dp">
                    <TextView
                        android:id="@+id/textView"
                        android:layout_width="100dp"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:singleLine="true"
                        android:textAlignment="textStart"/>
        </LinearLayout>
    </FrameLayout>

댓글