ssomai / ScalableLayout

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

EditText에서 textview_wrapcontent_direction 사용 질문 드립니다. #55

Closed kimkyungmi closed 6 years ago

kimkyungmi commented 6 years ago

xml 파일에 EditText 를 두고 java 파일에서 setText를 이용하여 텍스트를 노출하는 기능을 구현 중에 있습니다.

setText 시에 텍스트의 길이가 EditText의 width보다 짧으면 한줄로 잘 표시가 되지만 width보다 길면 첨부파일과 같이 한줄 이상으로 표시되며 잘려서 보입니다.

default

해당 현상을 수정하고자 EditText의 속성을 추가하였습니다.

    <EditText
        android:id="@+id/edit_subject"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bg_border"
        android:ems="10"
        android:padding="8dp"
        sl:scale_height="100"
        sl:scale_left="270"
        sl:scale_textsize="45"
        sl:scale_top="270"
        sl:scale_width="700"
        sl:textview_wrapcontent_direction="bottom"
        sl:textview_wrapcontent_resizesurrounded="true"
        sl:textview_wrapcontent_movesiblings="false" />

그런데 화면 처음 진입 시에는 현상이 유지되고 해당 EditText를 터치해야지만 영역이 넓어집니다.

화면 처음 진입 시에 영역이 넓어진 상태로 노출되도록 하는 속성은 없는지 해결 방법 공유 부탁드립니다ㅠㅠ..

ssomai commented 6 years ago

안녕하세요 onCreate나 다른 시작부분에서 (ScalableLayout).requestLayout()이나 (ScalableLayout).forceLayout() 호출해봐주시겠어요~?

kimkyungmi commented 6 years ago
  1. ScalableLayout scalable_layout = (ScalableLayout)findViewById(R.id.scalable_layout); scalable_layout.requestLayout();

  2. ScalableLayout scalable_layout = (ScalableLayout)findViewById(R.id.scalable_layout); scalable_layout.forceLayout();

두가지 다 해보았는데 적용되지 않ㄴㅔ요ㅠㅠ..

이렇게 사용하는 것이 아닌가요..?

ssomai commented 6 years ago

아 그럼 혹시 edittext에 settext하고 난이후에 호출해보시겠어요?

kimkyungmi commented 6 years ago

setText 이후에 호출하여도 적용되지 않습니다ㅠㅠ..

방법을 조금 달리해볼까 하는데...

화면을 다시 그리는게 아니라 editText의 setText 시에 라인 수를 체크하여 1줄 이상인 경우엔 height 값을 변경하려 합니다.

                edit_subject.setText(response.body().response.subject);

                if( edit_subject.getLineCount() > 1 ){
                    edit_subject.setHeight(200);
                }

setHeight 는 현재 scalableLayout 때문에 적용되지 않는 것 같은데... scalableLayout 자체에 height 변경 속성이 있는지 문의드립니다^^ (scalableLayout 자식뷰의 height 변경입니다...)

EditText 속성은 아래와 같습니다.

        <EditText
            android:id="@+id/edit_subject"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:background="@drawable/bg_border"
            android:ems="10"
            android:padding="8dp"
            sl:scale_height="100"
            sl:scale_left="270"
            sl:scale_textsize="45"
            sl:scale_top="270"
            sl:scale_width="700" />

확인 부탁드립니다 :)

ssomai commented 6 years ago

네, ScalableLayout에서 자식뷰들의 Width와 Height를 관리합니다.

훔... 그럼 한번 setText이후에 100ms정도 delay를 줘서 requestLayout, forceLayout을 해보시겠어요? ; ScalableLayout이랑 EditText 둘다 해봐주세요.

kimkyungmi commented 6 years ago

해결하였습니다 :)

  1. scalable_layout.requestLayout();
  2. edit_subject.requestLayout();

setText 이후에 1번을 추가한 경우에 적용되지 않았지만 2번을 추가한 경우에는 알맞게 적용되었습니다. (delay 후에 적용과 setText 직후에 적용 모두 ok)

(1번 추가 시에 왜 적용이 되지 않는지는 좀 더 원인 분석이 필요할 것 같습니다..)

도움 주셔서 감사합니다. 즐거운 오후 되세요

ssomai commented 6 years ago

아 다행이네요 1번이 안 되는건 아마 edittext의 text가 layout에 아직 적용이 안 되서인것 같네요~. edittext의 requestLayout이 맞았나 봅니다. 아 그리고 delay 없이도 한번 테스트해보세요~.