2013-03-14 2 views
2

작은 응용 프로그램에 관한 문제가 생겼습니다. 사용자 지정 가로 목록보기를 사용하고 있는데 가로 목록보기를 만들기 위해 아래 링크를 따라 왔습니다. 누군가가 나를 도울 수가로 목록보기 배경

및 XML 레이아웃은 .. 같은

<com.example.HorizontalListView 
     android:id="@+id/listview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:background="@android:color/transparent" 
     android:cacheColorHint="@android:color/transparent" 
     android:divider="@color/Black" 
     > 
    </com.example.HorizontalListView> 

하지만 문제는 내가 가로 목록보기의 배경을 변경할 수 없습니다 입니다 .. @ 사전에 감사합니다!

답변

0

동적으로 변경해보십시오.

Android 개발자 참조 페이지에서 View에 대한 API는 here을 클릭하십시오. 세 아래의 방법이 View 개체에 배경을 추가 할 수 있음을 명심하십시오 :

public void setBackground (Drawable background); 
public void setBackgroundColor (int color); 
public void setBackgroundResource (int resid); 

에서 onCreate :

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.listviewdemo); 

    HorizontialListView listview = (HorizontialListView) findViewById(R.id.listview); 
    listview.setAdapter(mAdapter); 

} 

BaseAdapter :

private BaseAdapter mAdapter = new BaseAdapter() { 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     View retval = LayoutInflater.from(parent.getContext()).inflate(R.layout.viewitem, null); 
     retval.setBackgroundResource(R.id.my_background); // add this line 

     return retval; 
    } 

}; 
+0

빠른 응답을위한 @thanks .. 나는 그걸 시도했으나 작동하지 않습니다! 이미지가보기 아래에 표시됩니다. –

+0

멋진 ... 일합니다 .. !!! –

0

나는이 해결책. 나는 HorizontalListView로 놀고있다. 먼저 viewitem.xml<LinearLayout> 태그 내에이 줄을 추가해야합니다

android:background="@android:color/transparent" 

그런 다음 listviewdemo.xml에서이 작업을 수행 : 당신이 이런 짓을하면

<com.devsmart.android.ui.HorizontalListView 
    android:id="@+id/listview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/background_you_want" 
/> 

가 제대로 당신이 HorizontalListView을 통해 보여주는 배경을 볼 수 있습니다. HorizontalListView는 전체 화면에도 걸쳐 있기 때문에 배경이 전체 화면에 걸쳐 펼쳐지며 의미가 있습니다.

희망이 도움이됩니다.