2010-08-26 5 views
1

Été bloqué sur cela pendant un moment et essayé quelques choses différentes.Android FrameLayout programmatique utilisé comme un bouton - comment remplir_parent?

Fondamentalement, j'ai surchargé la disposition des cadres pour créer moi-même un bouton personnalisé. La disposition du cadre a deux enfants un bouton et une disposition linéaire avec des éléments dedans. Le problème est que j'essaie d'obtenir le bouton pour s'étirer à la taille de la mise en page du cadre (c'est-à-dire remplir le parent) et cela ne fonctionne pas. Voici le code, il suffit de demander si vous voulez plus de détails:

public class ReminderButton extends FrameLayout{ 

private TextView text; 
private ImageView video; 
private ImageView pdf; 
public Button button; 
private LinearLayout itemsLayout; 

public ReminderButton(Context context, AttributeSet attrs) { 
super(context, attrs); 

this.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); 
this.setFocusable(false); 

LinearLayout itemsLayout = new LinearLayout(context); 
itemsLayout.setOrientation(LinearLayout.HORIZONTAL); 
itemsLayout.setFocusable(false); 
itemsLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); 
itemsLayout.setWeightSum(100); 

LinearLayout textLayout = new LinearLayout(context); 
textLayout.setFocusable(false); 
textLayout.setLayoutParams(new LinearLayout.LayoutParams(0,LayoutParams.FILL_PARENT, 80)); 
textLayout.setGravity(Gravity.CENTER); 

text = new TextView(context); 
text.setFocusable(false); 
text.setTextColor(Color.WHITE); 
text.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
text.setPadding(5, 3, 3, 3); 

LinearLayout imagesLayout = new LinearLayout(context); 
imagesLayout.setOrientation(LinearLayout.VERTICAL); 
imagesLayout.setFocusable(false); 
imagesLayout.setLayoutParams(new LinearLayout.LayoutParams(0,LayoutParams.FILL_PARENT, 20)); 
imagesLayout.setGravity(Gravity.CENTER); 

    video = new ImageView(context); 
    video.setFocusable(false); 
    video.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
    video.setImageResource(R.drawable.ic_video_small); 

    pdf = new ImageView(context); 
    pdf.setFocusable(false); 
    pdf.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
    pdf.setImageResource(R.drawable.ic_pdf_small); 

    // TODO this doesn't go big enough!   
    button = new Button(context); 
    button.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); 
    button.setBackgroundResource(R.drawable.custom_button); 

    // Add the text to its linear layout 
    textLayout.addView(text); 

    // Add the video and pdf icons to the vertical linear layout i.e. below each other 
    imagesLayout.addView(video); 
    imagesLayout.addView(pdf); 

    // Add the text and the layout containing the images to the horizontal linear layout i.e. next to each other 
    itemsLayout.addView(textLayout); 
    itemsLayout.addView(imagesLayout); 

    // Add the items layout and the buttons layout to the frame i.e. on items on top of the button 
    this.addView(button); 
    this.addView(itemsLayout); 
} 

Répondre

0

Vous ne trouvez pas une réponse, mais de le réparer, j'ai enlevé le bouton et vient de faire la base disposition linéaire cliquable

Questions connexes