2013-04-25 4 views
3

내 안드로이드 응용 프로그램의 ListView에있는 항목에 왼쪽에 체크 상자가 있고 그 다음에 텍스트가 나오고 단추가 있어야합니다. 확인란과 버튼을 기준선과 텍스트로 정렬하고 싶습니다. 이를 달성하기 위해 기본적으로 LinearLayout에 모든 항목을 기준선으로 정렬하려고합니다. 이것은 여러 줄 텍스트의 맨 아래 줄이 항상 잘리는 것을 제외하고는 훌륭하게 작동합니다. 여기 기준선 정렬 된 TextView 클립 복수 줄 텍스트의 아래쪽 줄

는 보이는 방법의 예입니다 :

Example of the problem

이 layout_gravity는 = 텍스트 뷰에 대한 "채우기"로 설정하는 것으로 제안 된 솔루션에 StackOverflow에 related question을있다, 그러나 그것은 목적을 패배 베이스 라인 정렬을 비활성화합니다. 베이스 라인 정렬을 유지할 수있는이 문제에 대한 해결책이 있습니까? 분명히 많은 사람들이 만나야 만하는 아주 기본적인 문제인 것 같습니다.

내가 찾은 유일한 해결책은 텍스트보기의 맨 아래에 약간의 패딩을 추가하는 것입니다.하지만이 방법은 글꼴 크기에 비해 튼튼하지는 않습니다. 나는 코드에서 글꼴 크기에 따라 패딩을 절차 적으로 설정할 수 있지만 올바른 값을 얻는 것이 까다로울 수 있습니다. 여기

문제를 도시하는 샘플 레이아웃이다

<?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:paddingBottom="8dp" 
    android:paddingTop="8dp" 
    android:baselineAligned="true"> 

    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="9dp" 
     android:layout_marginRight="8dp" 
     android:textSize="16sp"/> 

    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Woah, this is a long text line, enough that tit has to wrap to multiple lines, thus demonstrating our problem. In fact, it wraps to multiple lines! So many lines! I hope they all show up correctly!" 
      android:textSize="16sp"/> 

    <FrameLayout 
     android:layout_width="40dp" 
     android:layout_height="match_parent"> 

     <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="12dp" 
       android:src="@drawable/ic_note_check_delete"/> 
    </FrameLayout> 
</LinearLayout> 
+0

변경 텍스트 뷰 높이에서 아이디어? – StoneBird

+0

제안 해 주셔서 감사하지만 작동하지 않습니다. 실제로 "fill_parent"는 약간의 잘못된 이름이므로 "match_parent"로 변경 한 이유는 실제로 텍스트를 더 작게 만들고 클립을 더 많이 만듭니다. – alvion

+0

선형 레이아웃에서'android : layout_height'을'fill_parent'로 변경하면 도움이 될까요? 그것은 내 컴퓨터에서 클리핑을 해결하지만 그 변화가 프로젝트 요구 사항을 만족 시키거나 새로운 문제를 제기합니까? – StoneBird

답변

0

가 마침내 center_verticalTextView의 레이아웃을 변경하여 중력 유사한 문제를 해결했다.

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical" /> 

`fill_parent`에 https://stackoverflow.com/a/11246243/3681880