JohnathonZ 2016-06-07 01:57 采纳率: 0%
浏览 6501

Android的LinerLayout动态添加(addView)布局文件,不起效果??

package tech.together.Character.Components;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import java.util.List;

import tech.together.R;

/**

  • Created by think on 2016/6/5.
    */
    public class BecomeEmployeeSkills extends LinearLayout implements View.OnClickListener {

    private LinearLayout skills;

    //private LayoutParams param = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    private LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    private List editSkillsViews;

    public BecomeEmployeeSkills(Context context) {
    super(context);
    initView(context);
    }

    public BecomeEmployeeSkills(Context context, AttributeSet attrs) {
    super(context, attrs);
    initView(context);
    }

    private void initView(Context context) {
    View.inflate(context, R.layout.layout_become_employee_skills, this);

    findViewById(R.id.add).setOnClickListener(this);
    findViewById(R.id.submit).setOnClickListener(this);
    skills = (LinearLayout) findViewById(R.id.skills);
    

    }

    @Override
    public void onClick(View v) {
    switch (v.getId()) {
    case R.id.add:
    //TODO 使用EditSkillView
    Log.d("URL", "onClick()ADD");

View view2 = (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.view_edit_skill, skills, false);
view2.setLayoutParams(param);
skills.addView(view2);

            invalidate();
            skills.requestLayout();
            break;
        case R.id.submit:
            //TODO


            break;
    }
}

}

addView后用手机测试,点击按钮没有反应,也不报错,然后输出的是下面的log
06-07 09:47:39.350 8325-8325/tech.together D/URL: onClick()ADD
06-07 09:47:39.366 8325-8325/tech.together D/ColorDrawable: Color = -1118482, canvas = android.view.GLES20RecordingCanvas@2d50567e, mTintMode = SRC_IN, mTint = null, ColorDrawable = android.graphics.drawable.ColorDrawable@3e3c5c62
06-07 09:47:39.544 8325-8325/tech.together V/SettingsInterface: from settings cache , name = sound_effects_enabled , value = 0
0

真不知道是为什么原因,求解释!

  • 写回答

2条回答 默认 最新

  • Kelley_cfy 2016-06-07 02:32
    关注

    可以把R.layout.layout_become_employee_skills文件贴出来? BecomeEmployeeSkills这个的尺寸怎么设置的

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog