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

TabLayout 커스텀 했는데 동적 높이 조절이 잘 안됩니다.

0 추천

TabLayout 디자인을 커스터마이즈 하고싶어서 TabLaout하고 Tab을 커스터마이즈 했습니다.

Tab에 텍스트뷰가 들어있어서 텍스트가 길어지면 개행하면서 자동으로 탭의 Height도 늘어나게 하고싶습니다.

소스 첨부하겠습니다.

// 커스텀 레이아웃 custom_round_tab_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- CustomTabLayoutのHeaderContainer、タブの-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              xmlns:app="http://schemas.android.com/apk/res-auto"
              android:orientation="vertical">

    <android.support.design.widget.TabLayout
        android:id="@+id/tblCustomRoundTab"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:paddingTop="5dp"
        android:background="@color/MainBackgroundGrayColor"
        app:tabTextColor="@color/MainTextColor"
        app:tabSelectedTextColor="@color/MainTextColor">
    </android.support.design.widget.TabLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="4dp"
        android:background="@color/MainBackgroundColor"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/pagerCustomRoundTab"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.v4.view.ViewPager>
</LinearLayout>

// 커스텀 탭 custom_round_tab.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:minHeight="35dp"
    android:orientation="horizontal"
    android:layout_gravity="center"
    android:gravity="center"
    android:background="@drawable/tab_shape_round">

    <ImageView
        android:id="@+id/imvCustomTab"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:paddingTop="4dp"
        android:paddingBottom="4dp"
        android:paddingEnd="4dp"
        android:visibility="gone"/>
    <TextView
        android:id="@+id/txvCustomTab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textAlignment="center"
        android:textSize="12dp"
        android:text="dummy"
        android:paddingEnd="4dp"
        android:textColor="#FFFFFF"/>
</LinearLayout>

//TabLayout에 Viewpager랑 Tab을 설정하는 CustomRoundTabLayout.java extend LiniearLayout

아래와 같은 결과가 나옵니다.(원하는 결과)

기본 저 사이즈로 표시하고 Tab안의 공간이 부족하면 Tab이 세로로 길어지면 OK입니다.

그래서  Custom_round_tab_layout.xml을 아래와 같이 고첬습니다.

<android.support.design.widget.TabLayout
    android:id="@+id/tblCustomRoundTab"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="35dp"
    android:paddingTop="5dp"
    android:background="@color/MainBackgroundGrayColor"
    app:tabTextColor="@color/MainTextColor"
    app:tabSelectedTextColor="@color/MainTextColor">
</android.support.design.widget.TabLayout>

그 결과 아래와 같이 됩니다...

Tab의 사이즈에 맞춰서 wrap_content해주길 바라는데...제 멋대로 저렇게 커집니다. Tab의 사이즈가 지금 표시된 저 사이즈보다 커지면 Tablayout도 자동으로 커저서 원하는 동작을 해주는데..문제는 기본사이즈를 35정도로 하고싶은데 tab의 사이즈가 35일떄도 지멋대로 저 사이즈까지 커저버립니다.

도대체 모르겠네요 아시는분 계시나요 ㅜ

gs낭천 (340 포인트) 님이 2018년 1월 26일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...