2016-06-25 2 views
2

다음 코드를 사용하고 중력을 첫 번째 텍스트 뷰 center으로 설정하면 자동으로 두 번째 textview의 텍스트도 첫 번째 텍스트 뷰의 텍스트와 정렬됩니다. 내가 top가로형 선형 레이아웃에서 두 텍스트 뷰의 다른 중력

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="96dp" 
     android:text="New Text" 
     android:id="@+id/textView" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="48dp" 
     android:text="New Text" 
     android:id="@+id/textView2" /> 
</LinearLayout> 

에 두 번째보기의 중력을 설정하더라도하지만 다른있는 LinearLayout에 2 텍스트 뷰를 포장 말한다 another question의 솔루션이 있었다. 그런데 왜 그렇게됩니까?

+0

대신 2 선형 레이아웃을 사용하면 relativelayout을 사용하십시오. 단지 2 센트. –

+0

LinearLayout은 뷰를 하나씩 (세로/가로) 정렬 할 수 있음을 의미합니다. 시퀀스 방식으로 초기화하는 방법. – sushildlh

답변

2

가로 LinearLayout은 기본값으로 자식 View을 기준선으로 정렬하므로 두 번째 문자 TextView이 첫 번째 문자와 정렬되도록 이동됩니다. 문제를 해결하려면 LinearLayoutbaselineAligned 속성을 false으로 설정하면됩니다.

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:baselineAligned="false"> 
관련 문제