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

xml 레이아웃에서 계층구조가 너무 많으면 안좋나요?

0 추천

리스트뷰에 넣을 아이템 xml을 만들고 있는데요,,(리사이클러뷰를 요즘 거의 사용한다는걸 알지만 리스트뷰를 먼저 공부하고 리사이클러뷰를 공부하면 도움된다고해서 이걸로 진행하고있습니다)

부스트코스에서 진행하는 단계별 프로젝트를 하면서 공부중인데 해당 단계에서 요구하는 아이템xml페이지는 만들었습니다.(제가 해당사진)

그런데 보시다시피 아이템 xml이라 정말 간단한데..

제가 원하는대로 구현하려다보니 완성된 디자인에 비해서 바닥의 회색선 하나를 추가하려고 Lienarlayout을 하나더 추가했더니 계층구조가 많이 생겼습니다...

보이는거에 비해 xml 코드양이 많아지니 비효율적인거같은데 계층구조가 많아져도 디자인만 완성되면 장땡인가요..?

아래 코드는 위 디자인의 작성코드입니다.

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/user" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="15dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="kym71**"
                android:textStyle="bold"
                android:textColor="@color/black"/>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center_vertical">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="10분전"/>
                <RatingBar
                    android:id="@+id/ratingBar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:numStars="5"
                    android:rating="5.0"
                    android:stepSize="0.1"
                    style="?android:attr/ratingBarStyleSmall"/>
            </LinearLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/comment"
                android:textSize="17dp"
                android:textStyle="bold"
                android:textColor="@color/black"/>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="추천 0 "/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="신고하기"/>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="3dp"
        android:background="@drawable/linearlayout_horizontal_line"/>
</LinearLayout>

 

codeslave (3,940 포인트) 님이 2020년 9월 2일 질문

2개의 답변

+1 추천
간단하게 안 좋습니다.

기본적으로 화면에 개별 view의 settext등의 작업을 할때.. 내부적에서 화면을 그리기 위해서는 상위 viewgroup에 올라가서 전체 하위 그룹의 ondraw 메서드를 호출하게 됩니다. 이게 뷰가 tree 구조의 형태를 띄는데 depth가 깊어지면 성능상 안 좋습니다. 그래서, 가급적 flat으로 가게 가이드를 하고 있고, contraintlayout을 밀고 있는 이유가 flat하게 view를 배치하기 쉽게 도와줍니다.
mcsong (44,040 포인트) 님이 2020년 9월 4일 답변
0 추천
당연히 간단한게 좋긴 할거에요. 실제로 레이아웃 계층 구조가 너무 깊으면 안드로이드 스튜디오에서 주의사항이 표시되기도 하구요(아마 10단계 쯤으로 기억합니다).

저정도는 아무 문제 없어보이네요
버닝 (4,880 포인트) 님이 2020년 9월 3일 답변
감사합니다..^^문제없이 사용해도 되겠네요!
...