2013-07-09 93 views
0

我有一個令人難以置信的問題TextViewListViewTextView第一排ListView在Android 4.2.2上有黑色。 (Nexus 4)在Android 4.2.1以上,它沒有顏色。在我的HTC One上一切正常,直到我收到更新到4.2.2。現在TextView s的前兩行有黑色背景。來自Nexus的第一行黑色的screenshot表示更多。適配器的Android 4.2.2上的黑色背景

代碼如下:

public class NotificationsAdapter extends ArrayAdapter<Object> { 

private ArrayList<Object> items; 
Context context;  
private LayoutInflater mInflater; 
Typeface rb; 
Typeface bn; 
Typeface rr; 
Typeface rbc; 

public NotificationsAdapter(Context context, int textViewResourceId, ArrayList<Object> items) { 
     super(context, textViewResourceId, items);  
     this.context = context;    
     this.items = items; 
     mInflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     rb = Typeface.createFromAsset(getContext().getAssets(), "Roboto-Bold.ttf"); 
     bn = Typeface.createFromAsset(getContext().getAssets(), "BebasNeue.otf"); 
     rr = Typeface.createFromAsset(getContext().getAssets(), "Roboto-Regular.ttf"); 
     rbc = Typeface.createFromAsset(getContext().getAssets(), "Roboto-BoldCondensed.ttf"); 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) {  

     int type; 
     if(items.get(position).getClass().equals(String.class)) 
      type = 0; 
     else 
      type = 1;   

     if(type == 0){ 
      String m = (String)items.get(position); 
      if (m != null) {     
       convertView = mInflater.inflate(R.layout.notification_month_row, null); 
       TextView month_date = (TextView)convertView.findViewById(R.id.tw_notification_month); 
       month_date.setTypeface(rb); 
       month_date.setText(m);      
      } 
     } 
     else{       
      Notifications o = (Notifications)items.get(position); 
      if (o != null) { 
       convertView = mInflater.inflate(R.layout.notification_row, null); 
       TextView month_date = (TextView)convertView.findViewById(R.id.tw_notification_date); 
       TextView title = (TextView)convertView.findViewById(R.id.tw_notification_title); 
       TextView note = (TextView)convertView.findViewById(R.id.tw_notification_description); 
       ImageView mark = (ImageView)convertView.findViewById(R.id.iv_notification_marker); 
       title.setTypeface(bn); 
       title.setText(o.getTitle());      
       note.setTypeface(rr); 
       note.setText(o.getDescription());      
       month_date.setTypeface(rbc); 
       month_date.setText(o.getDate());       
       if(o.getConfirmed().equals("1")){ 
        mark.setVisibility(4); 
       }else{ 
        mark.setVisibility(0); 
       }          
      } 
     } 

     return convertView; 
    } 

有誰有它爲什麼發生任何想法?

XML這裏:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_margin="0dp" 
android:paddingTop="0dp" 
android:paddingBottom="25dp"  
android:background="@drawable/background_cell_profile"  
>  


<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 
<TextView 
     android:id="@+id/tw_notification_title"    
     android:layout_toLeftOf="@+id/tw_notification_date" 
     android:layout_alignParentLeft="true" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"    
     android:layout_marginTop="25dp"   
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:lines="1"  
     android:singleLine="true" 
     android:ems="3"  
     android:ellipsize="end"   
     android:textSize="27sp" 
     android:textColor="#ffffff" 
     android:shadowColor="#000000" 
     android:shadowDy="-2" 
     android:shadowRadius="0.1" 
     android:clickable="false" 
     android:focusable="false"/> 

<TextView 
     android:id="@+id/tw_notification_date" 
     android:layout_marginTop="25dp" 
     android:layout_alignParentRight="true"   
     android:layout_marginLeft="10dp"    
     android:layout_marginRight="10dp"   
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"        
     android:textSize="20sp" 
     android:textColor="#ffffff" 
     android:shadowColor="#000000" 
     android:shadowDy="-2" 
     android:shadowRadius="0.1" 
     android:clickable="false" 
     android:focusable="false"/> 

<TextView 
     android:id="@+id/tw_notification_description" 
     android:layout_below="@+id/tw_notification_title" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"    
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp"         
     android:textSize="14sp" 
     android:textColor="@color/gray_to_white" 
     android:shadowColor="#000000" 
     android:shadowDy="-2" 
     android:shadowRadius="0.1" 
     android:clickable="false" 
     android:focusable="false"/>  
</RelativeLayout> 

<ImageView 
    android:id="@+id/iv_notification_marker" 
    android:layout_width="40dp" 
    android:layout_height="40dp" 
    android:padding="0dp" 
    android:layout_marginTop="0dp" 
    android:layout_gravity="right|top" 
    android:src="@drawable/icon_oznameni_unreadindicator"/> 

+0

您可以發佈自定義列表視圖項目的XML文件嗎? – Nick

+0

我在XML上面張貼了 – dostalleos

+0

它是由陰影引起的,因爲它是用陰影顏色改變顏色的。但我仍然不知道它爲什麼只發生在Android 4.2.2上的第一行或第一行+第二行 – dostalleos

回答

0

不知道這是否會幫助,但你不正確使用LayoutInflater:

convertView = mInflater.inflate(R.layout.notification_month_row, null); 

它應該是:

convertView = mInflater.inflate(R.layout.notification_month_row, parent, false); 

使用fo rmer有時會給我奇怪的渲染問題。

請參閱this blog post

+0

謝謝,我試過了,但是我在title.setTypeface(bn);上得到了NullPointerException。佈局中的UI組件爲空:( – dostalleos