2012-10-21 2 views
0

나는 간단한 안드로이드 애플 리케이션을 개발하려고합니다. 검색 기준을 입력하기위한 두 개의 텍스트 상자가 있습니다. 페이지를 제출하기위한 제출 버튼. 다음 페이지 (새로운 의도)에서 검색 결과를 보여줍니다.android list view - 행 색상

이제 결과를 목록보기로 검색하고 싶습니다. 보기의 xml 코드는 다음과 같습니다. XXXArrayAdapter 클래스에서

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:padding="5dp"> 

<ImageView 
    android:id="@+id/image" 
    android:layout_width="50px" 
    android:layout_height="50px" 
    android:layout_marginLeft="5px" 
    android:layout_marginRight="20px" 
    android:layout_marginTop="5px"> 
</ImageView> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:padding="5dp" 
android:orientation="vertical"> 

<TextView 
    android:id="@+id/label" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@+id/label" 
    android:textSize="15px" > 
</TextView> 
<TextView 
    android:id="@+id/addr" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@+id/label" 
    android:textSize="15px" > 
</TextView> 

은의 getView 방법은, I는 다음과 배경색을 설정합니다.

private int[] colors = new int[] { 0x30FF0000, 0x300000FF }; 
int colorPos = position % colors.length; 
rowView.setBackgroundColor(colors[colorPos]); 

그러나 전체 행을 채우는 백 골색을 볼 수 없습니다. 아래 스크린 샷을 참조하십시오. 빨간색 상자는 무시하고 의도적으로 검색 결과를 숨기고 있습니다.

답변

1

레이아웃의 루트 LinearLayout 너비가 내용을 줄 바꾸기로 설정되었습니다. 전체 화면을 채울 수 있도록 match_parent로 설정하십시오.

<?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:padding="5dp"> 
+1

어디에서 안드로이드 컬러 코드를 찾을 수 있습니까? – crazyTechie

+0

android.graphics.Color 클래스에서 정적 색상을 사용할 수 있습니다. 예 : int colorRed = Color.RED; Color.parseColor ("# ff00ff");를 사용하여 16 진수 코드에서 색상을 파싱 할 수도 있습니다. – dymmeh