2016-04-20 7 views
0

Benutzerdefinierte Linearlayout Komponentensicht nicht Inhalt AnzeigeBenutzerdefinierte Komponente Android Linearlayout nicht sichtbar

Hallo, ich habe eine benutzerdefinierte Komponentensicht erstellt, das Linearlayout erstreckt und wenn ich diese Ansicht auf meiner xml verwenden, funktioniert es nicht auf dem Bildschirm sichtbar werden. Hier

ist die Hauptansicht, die diese benutzerdefinierte Komponente

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/contentLinearLayout" 
    android:layout_width="@dimen/width" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 


    <ImageView 
     android:id="@+id/image" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#ABB0B6" /> 

    <com.jon.ui.EnableView 
     android:id="@+id/enableContainter" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 

Hier ist die enableView benutzerdefinierte Komponente Code verwendet:

package com.jon.ui; 



/** 
*/ 
public class EnableView extends LinearLayout { 

    private static View enableView; 

    private static Button btnContactlessInfoAction; 
    private static LinearLayout btnMakeContactlessAction; 
    private static View makeContactlessView; 


    private static View.OnClickListener enableContaclessBtnClick = new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

     } 
    }; 

    private static View.OnClickListener contactlessHelpBtnClick = new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

     } 
    }; 
    private static ViewGroup viewContainer; 
    private final Context mContext; 

    public EnableContactlessView(Context context) { 
     super(context); 
     mContext = context; 
     LayoutInflater inflater = (LayoutInflater) context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     inflater.inflate(R.layout.custom_component, this); 
     setOrientation(LinearLayout.VERTICAL); 
    } 

    public EnableContactlessView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     mContext = context; 
     LayoutInflater inflater = (LayoutInflater) context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     inflater.inflate(R.layout.custom_component, this); 
     setOrientation(LinearLayout.VERTICAL); 
    } 


    @Override 
    protected void onAttachedToWindow() { 
     super.onAttachedToWindow(); 

    } 

    public void initiate() { 

      btnMakeContactlessAction = (LinearLayout) this.findViewById(R.id.btn); 
      btnContactlessInfoAction = (Button) this.findViewById(R.id.info_btn); 
      btnContactlessInfoAction.setOnClickListener(contactlessHelpBtnClick); 


    } 




    @Override 
    protected void onLayout(boolean changed, int l, int t, int r, int b) { 

    } 
} 

unten ist die Ansicht Layout xml i von enableView aufzublasen verwenden Klasse genannt custom_component.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="@dimen/top_margin" 
    android:gravity="center_horizontal" 
    android:orientation="horizontal"> 

    <LinearLayout 
     android:id="@+id/btn" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="9dp" 
     android:layout_weight="3" 
     android:background="@color/button_colour" 
     android:gravity="center" 
     android:paddingBottom="9dp" 
     android:paddingTop="9dp"> 


     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="15dp" 
      android:src="@drawable/icon_symbol" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="activate and enable" 
      android:textColor="@android:color/white" /> 
    </LinearLayout> 


    <Button 
     android:id="@+id/info_btn" 
     android:layout_width="25dp" 
     android:layout_height="25dp" 
     android:layout_gravity="center_vertical|end" 
     android:background="@drawable/icon" /> 


</LinearLayout> 

Antwort

3

Do überschreiben Sie onLayout nicht, wenn Sie es leer lassen, entfernen Sie diese Funktion. onLayout wird verwendet, um das Elternelement und seine untergeordneten Elemente zu messen. Wenn Sie es leer lassen, wird nichts gemessen.

Verwandte Themen