Android <android:Text> Tag Not Working
특정 TextView에 ViewModel에서 사용중인 데이터를 DataBinding을 이용해 TextView에 표시해주는 기능이 동작을 안한다고 전달 받았다.
해당 내용에 대해 확인해봤을 때, ViewModel에 데이터는 정상적으로 들어가 있는데 TextView에는 표시가 안되고 있음을 확인했다.
'대체 왜 안들어가지.. 데이터는 있고, 문법도 틀리지 않았는데..' 라고 생각하여 One way binding을 Two way binding으로도 바꿔보고, 이름도 바꿔보고.. 별짓을 다해도 안됐다.
'아니 지금 이 TextView가 정상적으로는 작동 하는건가?' 라는 생각에 로그에 해당 TextView에 Text를 뿌려보기도 했다.
역시나 빈값..
그렇다면, 'TextView Tag에 android:Text를 고정으로 아무 값이나 박아보자' 했을 때에도 표시가 안됐다.
'아니.. 오류도 없고, 다른 TextView Tag를 살펴봐도 다 똑같이 썼는데 대체 왜?' 라고 생각하던 차에 Design을 열어 해당 TextView를 봤는데, 내가 원하는대로의 크기가 아니더라.
즉, TextView Tag를 이용해 생성은 하였으나 크기가 주어지지 않아 소멸(?) 된 것 같았다.
해당 TextView에 Width를 match_parent로 조정하니 정상적으로 작동했다.
근데 아직도 이 코드가 왜 안되는지 모르겠다.
내가 width를 '0dp'로 줬었는데, 0dp는 부모의 크기에 따라 맞추겠다는 의미가 아니였나..?
근데 왜 다른건 잘 크기가 주어져있는지 모르겠다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/date_wrap"
android:layout_width="0dp"
android:layout_height="33dp"
android:layout_marginTop="10dp"
android:layout_marginStart="7dp"
android:layout_marginEnd="5dp"
android:background="@drawable/task_wrap_blue"
android:orientation="horizontal"
android:padding="1dp"
app:layout_constraintTop_toBottomOf="@id/lookup_wrap"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/date_title">
<TextView
android:id="@+id/date_text"
android:layout_width="0dp"
android:layout_height="33dp"
android:layout_marginStart="4dp"
android:includeFontPadding="false"
android:text="@{vm.date}"
tools:text="2021.01.01"
android:textSize="22sp"
android:textColor="#d1d1d1"
android:textAlignment="center"
android:fontFamily="@font/notosanscjkkr_light"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/date_up"/>
...
</androidx.constraintlayout.widget.ConstraintLayout>
|
cs |
위에꺼는 잘 되고..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cname_wrap"
android:layout_width="0dp"
android:layout_height="33dp"
android:layout_marginTop="5dp"
android:layout_marginStart="7dp"
android:layout_marginEnd="5dp"
android:orientation="horizontal"
android:padding="1dp"
app:layout_constraintTop_toBottomOf="@id/date_wrap"
app:layout_constraintStart_toEndOf="@id/name_title"
app:layout_constraintEnd_toEndOf="parent">
<TextView
android:id="@+id/name_text"
android:layout_width="0dp"
android:layout_height="33dp"
android:includeFontPadding="false"
android:textSize="22sp"
android:layout_marginStart="4dp"
android:textColor="#d1d1d1"
android:text="@{vm.testObj.NAME}"
android:fontFamily="@font/notosanscjkkr_light"
android:textAlignment="center"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
|
cs |
이건 안된다.
16번째 라인에 width를 'match_parent'로 변경하니 잘 작동했다.
이유를 모르겠다.