2017-02-01 8 views
0

Hier ist mein list_section.xml Code:Ansicht wird nicht angezeigt, wenn das Layout aufgeblasen wird

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginBottom="1dp" 
android:background="@color/colorBackgroundDark" 
android:paddingBottom="10dp" 
android:paddingTop="10dp"> 

<TextView 
    android:id="@+id/textViewAssessmentTypeName" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="left" 
    android:paddingLeft="16dp" 
    android:textColor="@color/colorPrimaryText" /> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#8000FF00" /> 
</RelativeLayout> 

ich es in meinem RecyclerViewAdapter durch bin Aufpumpen:

@Override 
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
    ... 
    else if (viewType == TYPE_SECTION) { 
     View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_section, parent, false); 
     return new ViewHolderSection(view, callback); 
    } 
    ... 
} 

private class ViewHolderSection extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { 
    ItemClickListener callback; 
    TextView assessmentTypeName; 

    ViewHolderSection(View view, ItemClickListener callback) { 
     super(view); 
     this.callback = callback; 
     assessmentTypeName = (TextView) view.findViewById(R.id.textViewAssessmentTypeName); 
     view.setOnClickListener(this); 
     view.setOnLongClickListener(this); 
    } 

    @Override 
    public void onClick(View v) { 
     if (callback != null) { 
      callback.onItemClick(getAdapterPosition()); 
     } 
    } 

    @Override 
    public boolean onLongClick(View v) { 
     if (callback != null) { 
      callback.onItemLongClick(getAdapterPosition()); 
     } 
     return true; 
    } 
} 

Aber aus irgendeinem Grund die Ansicht in layout.xml, das ich als Farbfilter/Overlay über RelativeLayout verwende, wird nicht angezeigt. Was könnte das Problem sein?

Antwort

0

ich es behoben, indem list_section.xml zu:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="40dp" 
android:background="@color/colorBackgroundDark"> 

<TextView 
    android:id="@+id/textViewAssessmentTypeName" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true" 
    android:gravity="left" 
    android:paddingLeft="16dp" 
    android:textColor="@color/colorPrimaryText" /> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#8000FF00" /> 
</RelativeLayout> 

die vorherige hat nicht funktioniert, weil die layout_height von RelativeLayout up endete als 0.

Verwandte Themen