Android设计依赖性

Android设计依赖性,android,android-layout,Android,Android Layout,我动态创建了LinearLayout,并将背景设置为可在该布局中绘制 当该布局空闲时,它看起来很好 问题是,当我单击用户名编辑文本时,布局已拆分 当我单击密码编辑文本时,布局崩溃 如果可以解决,请给出一些建议 可绘制:button_shape.xml <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"

我动态创建了LinearLayout,并将背景设置为可在该布局中绘制

当该布局空闲时,它看起来很好

问题是,当我单击用户名编辑文本时,布局已拆分

当我单击密码编辑文本时,布局崩溃

如果可以解决,请给出一些建议

可绘制:button_shape.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#ffffffff"/> 
   <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" 
     android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape>

注:

用户名和密码是分开的LinearLayout

登录和注册按钮是单独的线性布局

动态线性布局代码

LinearLayout mainlayout = new LinearLayout(con);
        mainlayout.setOrientation(1);
        mainlayout.setBackgroundDrawable(drawable);

        for(int i=0;i<data.size();i++){
            TextView tv = new TextView(con);
            EditText et = new EditText(con);
            tv.setText(data.get(i));
            tv.setHeight(50);
            tv.setPadding(22, 0, 0, 0);
            tv.setTextColor(0xff000000);
            mainlayout.addView(tv);
            et.setHint("Tap To Type");
            mainlayout.addView(et);
        }

LinearLayout main布局=新的LinearLayout(con);
主布局。设置方向(1);
主布局。可拉拔(可拉拔);

对于(int i=0;i您已将背景应用于用户名和密码布局。同样,请尝试将背景应用于
editText
。如果您不这样做,则
editText
将使用其默认属性,并在关注时与其父级一起折叠。希望有帮助

编辑:我自己,我运行代码。它运行良好

LinearLayout mainlayout = new LinearLayout(this);
    mainlayout.setOrientation(1);
    mainlayout.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_xml));

    for(int i=0;i<2;i++){
        TextView tv = new TextView(this);
        EditText et = new EditText(this);
        tv.setText(""+i);
        tv.setHeight(50);
        tv.setPadding(22, 0, 0, 0);
        tv.setTextColor(0xff000000);
        mainlayout.addView(tv);
        et.setHint("Tap To Type");
        et.setBackgroundDrawable(getResources().getDrawable(R.drawable.normal));
        mainlayout.addView(et);
    }

    addContentView(mainlayout, new LinearLayout.LayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)));

LinearLayout main布局=新的LinearLayout(此布局);
主布局。设置方向(1);
setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_xml));

对于(int i=0;i您已将背景应用于用户名和密码布局。同样,请尝试将背景应用于
editText
。如果您不这样做,则
editText
将使用其默认属性,并在关注时与其父级一起折叠。希望有帮助

编辑:我自己,我运行代码。它运行良好

LinearLayout mainlayout = new LinearLayout(this);
    mainlayout.setOrientation(1);
    mainlayout.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_xml));

    for(int i=0;i<2;i++){
        TextView tv = new TextView(this);
        EditText et = new EditText(this);
        tv.setText(""+i);
        tv.setHeight(50);
        tv.setPadding(22, 0, 0, 0);
        tv.setTextColor(0xff000000);
        mainlayout.addView(tv);
        et.setHint("Tap To Type");
        et.setBackgroundDrawable(getResources().getDrawable(R.drawable.normal));
        mainlayout.addView(et);
    }

    addContentView(mainlayout, new LinearLayout.LayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)));

LinearLayout main布局=新的LinearLayout(此布局);
主布局。设置方向(1);
setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_xml));

对于(int i=0;如果不包括动态创建
LinearLayout
并设置其可绘制背景的代码,您将很难获得帮助。如果不包括动态创建
LinearLayout
并设置其可绘制背景的代码,您将很难获得帮助。以下是我的动态linearlayout代码linearlayout mainlayout=新建linearlayout(con);mainlayout.setOrientation(1);mainlayout.setBackgroundDrawable(drawable);对于(int i=0;如果编辑文本et,则为mainlayout linearlayout mainlayout=新建linearlayout(con);mainlayout.setOrientation(1);mainlayout.setBackgroundDrawable(drawable);for(int i=0;i您是否将用于mainlayout的相同drawable设置为editText?尝试使用不同的、简单的、无任何角的drawable(使用正方形)因为您的父视图具有拐角背景,所以儿童内部的拐角背景可能会改变外观这里是我的动态linearlayout代码linearlayout mainlayout=新的linearlayout(con);mainlayout.setOrientation(1);mainlayout.setBackgroundDrawable(drawable);用于(int i=0;如果编辑文本et,则为mainLayoutLinearLayout将背景设置为u设置mainlayout=new LinearLayout(con);mainlayout.setOrientation(1);mainlayout.setBackgroundDrawable(drawable);用于(int i=0;i您是否将主布局中使用的相同可绘制文本设置为编辑文本?尝试使用不同的、简单的无角可绘制文本(使用正方形),因为您的父视图具有拐角背景,因此儿童内部的拐角背景可能会改变外观