2012-11-07 7 views
0

안녕하세요, 저는 ViewFlipper를 사용하여 2 개의 뷰 (하나의 뷰는 ImageView, 하나는 TextView)를 넘깁니다. 이미지와 텍스트의 크기는 서버에서 검색 한 내용에 따라 다릅니다. ImageView와 동일한 높이 치수를 항상 갖기를 원합니다. 그래야 이미지 뷰를 뒤집을 때 텍스트 뷰와 관련된 텍스트가 거의 없더라도 텍스트 뷰 레이아웃의 크기가 변경되지 않습니다 (많은 텍스트가있는 경우). TextView의 높이가 이미지 뷰를 초과하면 ellipsize = "end"를 원합니다. 거기에이 문제에 대한 간단한 솔루션입니다하지만 너무 오랫동안이 방법에 고군분투 같은 느낌ViewFlipper 내에서 뷰 정렬

<ViewFlipper 
    android:id="@+id/flipperZoneMediumLeft" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:id="@+id/imgZonePic" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/stock_service1" 
     android:background="@android:color/black" 
     android:scaleType="center" /> 

    <TextView 
     android:id="@+id/txtZoneNameFlipperLeft" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:ellipsize="end" 
     android:gravity="center" 
     android:text="This is a description" 
     android:background="@android:color/black" 
     android:textColor="@android:color/white" /> 
</ViewFlipper> 

: 아래 내 레이아웃에 사용하고있는 코드입니다. 내 문제를 해결할 수있는 도움을 주시면 감사하겠습니다.

감사합니다.

답변

0

ImageViewTextViewLinearLayout으로 감싸서 가중치를 적용 할 수 있습니다. 양쪽 모두의 높이를 0dp로 설정하고 각 layout_weight에 1을 지정합니다. 이렇게하면 항상 동일한 높이가됩니다. 이처럼 :

<ViewFlipper 
    android:id="@+id/flipperZoneMediumLeft" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" > 

      <ImageView 
       android:id="@+id/imgZonePic" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="@android:color/black" 
       android:scaleType="center" 
       android:src="@drawable/stock_service1" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" > 

      <TextView 
       android:id="@+id/txtZoneNameFlipperLeft" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="@android:color/black" 
       android:ellipsize="end" 
       android:gravity="center" 
       android:text="This is a description" 
       android:textColor="@android:color/white" /> 
     </LinearLayout> 
    </LinearLayout> 

</ViewFlipper> 
+0

당신은 LinearLayout' 그렇지 않으면 당신이 단지 만'의 LinearLayout에 동일한 높이를 가진'TextView'을'ImageView'으로 하나의 아이'ViewFlipper'으로 끝낼와 '그 자체에 각각의보기를 포장 할 필요가 '. – Luksprog

+0

@ Luksprog 아, 죄송합니다. 대답 – Ahmad

+0

을 편집 할 것입니다. 불행히도 내 문제를 해결하지 못했습니다. 위의 레이아웃을 사용하여 viewflipper가 두 개의 하위보기를 제대로 사용해야 만 이미지 뷰 아래에 내 textview를 배치 할 필요가 없습니다. – pkramaric