2014-02-10 3 views
2

머리글을 추가 한 목록보기가 있습니다. 그러나 머리글 주위에 목록보기 배경이 나타나지 않게하십시오.목록보기에서 머리글 배경을 제거하십시오.

- :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<com.example.tuto.customs.CustomHoverView 
    android:id="@+id/chv_activity_list_with_header" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ListView 
     android:id="@+id/lv_activity_list_with_header" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@drawable/carreblanc" 
     android:cacheColorHint="#00000000" 
     > 
    </ListView> 
</com.example.tuto.customs.CustomHoverView> 

</LinearLayout> 

헤더 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Header" /> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:adjustViewBounds="true" 
    android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

BaseAdapter 클래스가 두 개의 서로 다른 견해처럼

목록보기를 (내가있는 ScrollView 내부의 목록보기를 넣어하지 않음)

private class MyAdapter extends BaseAdapter{ 
    private LayoutInflater inflater; 
    private List<String> strings; 
    public MyAdapter(Context context, List<String> strings) { 
     inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     this.strings = strings; 
    } 

    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return strings.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     // TODO Auto-generated method stub 
     return strings.get(position); 
    } 

    @Override 
    public long getItemId(int position) { 
     // TODO Auto-generated method stub 
     return 0; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 
     View v = convertView; 
     ViewHolder h; 
     if(v == null){ 
      v = inflater.inflate(R.layout.adapter_strings, null); 
      h = new ViewHolder(); 
      h.tv = (TextView) v.findViewById(R.id.tv_adapter_strings); 
      v.setTag(h); 
     }else{ 
      h = (ViewHolder) v.getTag(); 
     } 
     if(position == 0){ 
        // here it changes the first item, but not the header 
      v.setBackgroundColor(Color.RED); 
     } 
     h.tv.setText(""+getItem(position)); 
     return v; 
    } 

    private class ViewHolder{ 
     TextView tv; 
    } 
} 

어댑터 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/tv_adapter_strings" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

</LinearLayout> 
+0

당신의 어댑터에서 이것을 처리하십시오, –

+0

더 설명 할 수 있습니까? – Tsunaze

+0

위치가 0 인 경우 getView 메서드에 대한 배경을 변경하고 위치가 0이 아닌 경우 다른 배경을 설정하십시오. –

답변

0

은 별도의 배경 header.xml를 만든 다음

LayoutInflater inflater = getLayoutInflater(); 
ViewGroup header = (ViewGroup)inflater.inflate(R.layout.header, myListView, false); 
myListView.addHeaderView(header, null, false); 

예를 당신의 활동에 here

+0

그게 내가 한 일이지만, 여전히 내 목록보기의 배경을 취합니다 – Tsunaze

+0

다른 배경색에 머리글 배경을 설정 했습니까? –

+0

아니, 난 그냥 listview 배경 – Tsunaze

0

header.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:background="@android:color/holo_blue_bright" 
> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Header" /> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:adjustViewBounds="true" 
    android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

쓰기이 참조리스트 뷰에 추가 할 수 있습니다 -

LayoutInflater inflater = getLayoutInflater(); 
      ViewGroup mTop = (ViewGroup) inflater.inflate(R.layout.header,listView,false); 
      listView.addHeaderView(mTop, null, false); 
+0

헤더 배경이 변경되었지만 원하는 것은 제거하는 것입니다. 다른 배경을 사용하더라도 뒤에서 listview의 배경을 볼 수 있습니다 – Tsunaze

+0

실제로 원하는 것은 무엇입니까 ?? – Namy

+0

제목과 마찬가지로 : 헤더의 배경을 제거하고 싶습니다. 목록보기에 포함되어 있기 때문입니다. – Tsunaze

관련 문제