ssomai / ScalableLayout

Scalable Layout For Android
Apache License 2.0
270 stars 87 forks source link

Listview질문있습니다. #48

Open Leesoohwan opened 7 years ago

Leesoohwan commented 7 years ago

정말 유용하게 사용하고있습니다. 그런데 리스트뷰를 쓸때 어려움이 있더라구요. activity_main에 LinearLayout을 두고 거기서 리스트뷰를 채우는걸로 생각했는데 item에서 설정값을 두니 LinearLayout을 벗어나는 걸로 나왔습니다. 잘 쓰고 싶은데 방법을 잘 모르겠습니다. 그거빼고는 완벽해요 ㅠㅠ 도와주시면 감사하겠습니다

ssomai commented 7 years ago

아! 이제야 봤네요 ㅠㅠㅠ

구체적으로 어떤 사례인지 코드로 설명을 부탁드려도 될까요? ㅠㅠ

Leesoohwan commented 7 years ago

간단하게 레이아웃 첨부해 드리겠습니다. 먼저 리스트뷰를 포함하는 money.xml입니다. <com.ssomai.android.scalablelayout.ScalableLayout xmlns:sl="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" sl:scale_base_width="1260" sl:scale_base_height="710"

<ListView android:paddingLeft="25dp" android:paddingTop = "10dp" android:paddingRight="25dp" android:paddingBottom="10dp" android:id="@+id/frame" android:background="@drawable/ranking_bg" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="#ffa021" android:dividerHeight="5dp" android:textColor="@android:color/black" sl:scale_textsize="30" sl:scale_left="0" sl:scale_top="80" sl:scale_height="630" sl:scale_width="1040" /> />

그리고, 이 리스트뷰에 불러올 user_score.xml입니다. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:padding="10dp" android:layout_height="match_parent"> <TextView android:id="@+id/userRank" android:text="순위" android:gravity="right" android:textColor="#a70725" android:layout_width="0dp" android:layout_weight="0.5" android:layout_height="wrap_content" android:textSize="30dp" />

<TextView
    android:id="@+id/userID"
    android:text="아이디"
    android:textColor="#00a7f5"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:textSize="30dp"
    />
<TextView
    android:id="@+id/userScore"
    android:text="점수"
    android:textColor="#f027ff"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:textSize="30dp"/>

위와 같이 짜면 당연히 Listview로 나오는 화면의 구성이 변하게 됩니다. 그런데, 저는 userRank, userID, userScore를 모두 sl:scale_textsize="20"과 같은 식으로 정해주고 싶은데 어디서 해야할지 모르겠습니다. ㅠㅠ

이 부분은 막혔지만 이 부분 제외하고는 만들어주신 ScalableLayout으로 모두 해결해서 잘 사용하고 있습니다. 미리 감사의 말씀 드립니다.^^

ssomai commented 7 years ago

상세히 적어주셔서 감사합니다~. 질문드릴게요~ 아래 TextView들이 ScalableLayout의 바로 child로 있나요? ScalableLayout포함해서 모든 Layout들은 자신의 바로 child view만 배치조정할수 있거든요~

Leesoohwan commented 7 years ago

아.. 이게 제가 질문이 잘못되었네요. 복사하면서 붙여서 그리되었나봅니다 ㅠㅠ.

  1. Money.xml: ScalableLayout의 차일드로 listview구성 리스트뷰에서 userscore를 getview로 가져옵니다(usescore를 inflate해서 가져옵니다)
  2. Userscore.xml: LinearLayout의 차일드로 textview세개를 가지고있습니다.

UserScore의 textview 세개를 어떻게 해야할지 모르겠습니다. Userscore.xml의 루트로 ScalableLayout으로 잡고 차일드로 textview로 잡는다면, money.xml에서 정한 listview와 사이즈와 똑같이 잡으면 해결될까요?? 그러기에는 listview의 textview의 y좌표가 변하기에 변수를 어떻게 넣어야 할지 모르겠구요. 리스트뷰를 어떻게하면 좋을지 궁금합니다.

ssomai commented 7 years ago

네, UserScore.xml의 루트로 ScalableLayout으로 잡으시면 됩니다~. 이 ScalableLayout의 사이즈는 자유입니다. ^^ 그런데 그 다음 '그러기에는 listview의 textview의 y좌표가 변한기에'에 대해서 이해를 못 했어요 ㅠㅠ 여기서 userscore는 하나의 독립적인 item이고 view이기 때문에 이 view만 보고 레이아웃하면 될것같습니다~. 스크롤은 알아서 될거구요~

Leesoohwan commented 7 years ago

제가 y좌표라고 말씀드린 것이 sl:scale_top이였습니다. ^^;; userscore는 독립적인 item이고 이것이 자동으로 들어가니까 sl:scale_top = 0으로 잡으면 되겠네요.; 저는 listView로 계속해서 추가되므로, sl:scale_top이 리스트뷰의 사이즈에 따라서 변해야하나 생각했습니다.^^;; 답장 계속주셔서 감사하구요, 한번 해보겠습니다. <com.ssomai.android.scalablelayout.ScalableLayout android:layout_width="match_parent" android:layout_height="match_parent" sl:scale_base_width="400" sl:scale_base_height="200"> <TextView android:id="@+id/userRank" sl:scale_left="0" sl:scale_top="0" sl:scale_width="100" sl:scale_height="30" sl:scale_textsize="20" android:text="점수" /> <TextView android:id="@+id/userRank" sl:scale_left="0" sl:scale_top="0" sl:scale_width="100" sl:scale_height="200" .. 중략 /> <TextView android:id="@+id/userId" sl:scale_left="100" sl:scale_top="0" sl:scale_width="200" sl:scale_height="200" .. 중략 /> <TextView android:id="@+id/userScore" sl:scale_left="200" sl:scale_top="0" sl:scale_width="400" sl:scale_height="200" .. 중략 /> /ScalableLayout>

Leesoohwan commented 7 years ago

고맙습니다. 위에 있는대로 적용하니 문제없이 잘 나오네요^^