Android编程式FrameLayout用作按钮-如何fill_parent? [英] Android programmatic FrameLayout used as a button - how to fill_parent?

查看:43
本文介绍了Android编程式FrameLayout用作按钮-如何fill_parent?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

曾经在此上停留了一段时间,并尝试了一些其他方法.

Been stuck on this for a while and tried a few various things.

基本上,我已经覆盖框架布局以创建一个自定义按钮.框架布局有两个子按钮和一个带有项目的线性布局.

Basically I've overridden frame layout to create myself a custom button. The frame layout has two children a button and a linearlayout with items in it.

问题是我试图将按钮拉伸到框架布局的大小(即填充父级),但没有这样做.这是代码,只问您是否需要更多详细信息:

The problem is I'm trying to the get the button to stretch to the size of the frame layout (i.e. fill parent) and it isn't doing. Here is the code, just ask if you want more detail:

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);
}

推荐答案

找不到答案,但是要解决这个问题,我删除了按钮,只是使基本线性布局可点击

Didn't find an answer, but to fix it , I removed the button and just made the base linear layout clickable

这篇关于Android编程式FrameLayout用作按钮-如何fill_parent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆