Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓相对论问题_Android_Android Relativelayout - Fatal编程技术网

Android 安卓相对论问题

Android 安卓相对论问题,android,android-relativelayout,Android,Android Relativelayout,我对相对定位有一些问题: 现在我有这个: 我希望: 这是我的密码: public class ActivityTwo extends Activity { RelativeLayout myRelativeLayout = null; ArrayList<ArrayList<EditText>> spreadsheet = new ArrayList<ArrayList<EditText>>(); @Override

我对相对定位有一些问题:

现在我有这个: 我希望:

这是我的密码:

public class ActivityTwo extends Activity {

    RelativeLayout myRelativeLayout = null;

    ArrayList<ArrayList<EditText>> spreadsheet = new ArrayList<ArrayList<EditText>>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.relativesprsheet);

        myRelativeLayout = (RelativeLayout)findViewById(R.id.relativeLayout);

        //FIRSTROW

        ArrayList<EditText> firstRow = new ArrayList<EditText>();

        char columnTitle = 'A';

        int prev_id = 0;

        for(int i = 0; i < 5; ++i) {
            EditText eText = new EditText(this);
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            eText.setWidth(100);
            eText.setId(getUniqueCellId(columnTitle,i + 1));
            if(i==0) {
                params.addRule(RelativeLayout.ALIGN_PARENT_LEFT,eText.getId());
                eText.setText("A1");
            }
            else {
                params.addRule(RelativeLayout.RIGHT_OF,prev_id);
                eText.setText(Character.toString(columnTitle)+Integer.toString(1));
            }
            prev_id = getUniqueCellId(columnTitle,i + 1);
            firstRow.add(eText);
            myRelativeLayout.addView(eText,params);
            columnTitle++;
        }

        spreadsheet.add(firstRow);

        //SECONDROW

        ArrayList<EditText> second_row = new ArrayList<EditText>();
        EditText a2 = new EditText(this);
        a2.setId(getUniqueCellId('A',2));
        a2.setWidth(100);
        a2.setText("A2");
        RelativeLayout.LayoutParams a2params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        a2params.addRule(RelativeLayout.BELOW, getUniqueCellId('A', 1));
        myRelativeLayout.addView(a2, a2params);
        second_row.add(a2);

        EditText bigView = new EditText(this);
        bigView.setId(getUniqueCellId('B', 2));
        bigView.setWidth(300);
        bigView.setText("B2");
        RelativeLayout.LayoutParams b2params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        b2params.addRule(RelativeLayout.RIGHT_OF, getUniqueCellId('A', 2));
        b2params.addRule(RelativeLayout.ALIGN_TOP,getUniqueCellId('A', 2));
        b2params.addRule(RelativeLayout.ALIGN_BOTTOM,getUniqueCellId('A', 4));
        b2params.addRule(RelativeLayout.ALIGN_RIGHT,getUniqueCellId('D',5));
        myRelativeLayout.addView(bigView, b2params);
        second_row.add(bigView);

        spreadsheet.add(second_row);

        //THIRDROW

        ArrayList<EditText> third_row = new ArrayList<EditText>();
        EditText a3 = new EditText(this);
        a3.setId(getUniqueCellId('A',3));
        a3.setWidth(100);
        a3.setText("A3");
        RelativeLayout.LayoutParams a3params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        a3params.addRule(RelativeLayout.BELOW, getUniqueCellId('A', 2));
        myRelativeLayout.addView(a3, a3params);
        third_row.add(a3);
        spreadsheet.add(third_row);

        //FOURTHROW

        ArrayList<EditText> fourth_row = new ArrayList<EditText>();
        EditText a4 = new EditText(this);
        a4.setId(getUniqueCellId('A',4));
        a4.setWidth(100);
        a4.setText("A4");
        RelativeLayout.LayoutParams a4params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        a4params.addRule(RelativeLayout.BELOW,  getUniqueCellId('A', 3));
        myRelativeLayout.addView(a4, a4params);
        fourth_row.add(a4);
        spreadsheet.add(fourth_row);

        //FIFTHROW

        ArrayList<EditText> fifth_row = new ArrayList<EditText>();
        EditText a5 = new EditText(this);
        a5.setId(getUniqueCellId('A',5));
        a5.setWidth(100);
        a5.setText("A5");
        RelativeLayout.LayoutParams a5params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        a5params.addRule(RelativeLayout.BELOW,  getUniqueCellId('A', 4));
        myRelativeLayout.addView(a5, a5params);
        fifth_row.add(a5);

        char c2 = 'B';
        for(int i = 1; i < 5; ++i) {
            EditText temp5Text = new EditText(this);
            temp5Text.setId(getUniqueCellId(c2,5));
            temp5Text.setWidth(100);
            temp5Text.setText(Character.toString(c2)+"5");
            RelativeLayout.LayoutParams temp5Textparams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
            temp5Textparams.addRule(RelativeLayout.RIGHT_OF,  getUniqueCellId((char)(c2-1), 5));
            temp5Textparams.addRule(RelativeLayout.ALIGN_TOP,  getUniqueCellId((char)(c2-1), 5));
            myRelativeLayout.addView(temp5Text, temp5Textparams);
            fifth_row.add(temp5Text);
            c2++;
        }

        spreadsheet.add(fifth_row);

    }

    private int getUniqueCellId(char c, int i) {
        return Integer.valueOf(c) * 10369 + i;
    }

}
公共类活动二扩展活动{
RelativeLayout myRelativeLayout=null;
ArrayList电子表格=新建ArrayList();
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.relativesprsheet);
myRelativeLayout=(RelativeLayout)findViewById(R.id.RelativeLayout);
//第一排
ArrayList firstRow=新的ArrayList();
char columnTitle='A';
int prev_id=0;
对于(int i=0;i<5;++i){
EditText-eText=新的EditText(此);
RelativeLayout.LayoutParams params=新的RelativeLayout.LayoutParams(LayoutParams.WRAP\u内容,LayoutParams.WRAP\u内容);
eText.setWidth(100);
setId(getUniqueCellId(columnTitle,i+1));
如果(i==0){
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT,eText.getId());
eText.setText(“A1”);
}
否则{
params.addRule(RelativeLayout.RIGHT\u OF,prev\u id);
setText.setText(Character.toString(columnTitle)+Integer.toString(1));
}
prev_id=getUniqueCellId(columnTitle,i+1);
第一行。添加(eText);
myRelativeLayout.addView(eText,params);
columnTitle++;
}
电子表格。添加(第一行);
//第二排
ArrayList第二行=新的ArrayList();
EditText a2=新的EditText(本);
a2.setId(getUniqueCellId('A',2));
a2.设定宽度(100);
a2.setText(“a2”);
RelativeLayout.LayoutParams a2params=新的RelativeLayout.LayoutParams(LayoutParams.WRAP\u内容,LayoutParams.WRAP\u内容);
a2params.addRule(RelativeLayout.down,getUniqueCellId('A',1));
myRelativeLayout.addView(a2,a2params);
第二行添加(a2);
EditText bigView=新的EditText(此);
setId(getUniqueCellId('B',2));
bigView.setWidth(300);
bigView.setText(“B2”);
RelativeLayout.LayoutParams b2params=新的RelativeLayout.LayoutParams(LayoutParams.WRAP\u内容,LayoutParams.WRAP\u内容);
b2params.addRule(RelativeLayout.RIGHT_OF,getUniqueCellId('A',2));
b2params.addRule(RelativeLayout.ALIGN_TOP,getUniqueCellId('A',2));
b2params.addRule(RelativeLayout.ALIGN_-BOTTOM,getUniqueCellId('A',4));
b2params.addRule(RelativeLayout.ALIGN_RIGHT,getUniqueCellId('D',5));
myRelativeLayout.addView(bigView,b2params);
第二行添加(大视图);
电子表格。添加(第二行);
//蒂德罗
ArrayList第三行=新建ArrayList();
EditText a3=新的EditText(本);
a3.setId(getUniqueCellId('A',3));
a3.设置宽度(100);
a3.setText(“a3”);
RelativeLayout.LayoutParams a3params=新的RelativeLayout.LayoutParams(LayoutParams.WRAP\u内容,LayoutParams.WRAP\u内容);
a3params.addRule(RelativeLayout.down,getUniqueCellId('A',2));
myRelativeLayout.addView(a3,a3params);
第三行。添加(a3);
电子表格。添加(第三行);
//四投
ArrayList第四行=新建ArrayList();
EditText a4=新的EditText(本);
a4.setId(getUniqueCellId('A',4));
a4.设置宽度(100);
a4.setText(“a4”);
RelativeLayout.LayoutParams a4params=新的RelativeLayout.LayoutParams(LayoutParams.WRAP\u内容,LayoutParams.WRAP\u内容);
a4params.addRule(RelativeLayout.down,getUniqueCellId('A',3));
myRelativeLayout.addView(a4、a4参数);
第四行加上(a4);
电子表格。添加(第四行);
//先进先出
ArrayList第五行=新建ArrayList();
EditText a5=新的EditText(本);
setId(getUniqueCellId('A',5));
a5.设定宽度(100);
a5.setText(“a5”);
RelativeLayout.LayoutParams a5params=新的RelativeLayout.LayoutParams(LayoutParams.WRAP\u内容,LayoutParams.WRAP\u内容);
a5params.addRule(RelativeLayout.down,getUniqueCellId('A',4));
myRelativeLayout.addView(a5,a5参数);
第五行添加(a5);
字符c2='B';
对于(int i=1;i<5;++i){
EditText temp5Text=新的EditText(本);
setId(getUniqueCellId(c2,5));
temp5Text.setWidth(100);
temp5Text.setText(Character.toString(c2)+“5”);
RelativeLayout.LayoutParams temp5Textparams=新的RelativeLayout.LayoutParams(LayoutParams.WRAP\u内容,LayoutParams.WRAP\u内容);
temp5Textparams.addRule(RelativeLayout.RIGHT_OF,getUniqueCellId((char)(c2-1),5));
temp5Textparams.addRule(RelativeLayout.ALIGN_TOP,getUniqueCellId((char)(c2-1),5));
myRelativeLayout.addView(temp5Text,temp5Textparams);
第五行。添加(temp5Text);
c2++;
}
电子表格。添加(第五行);
}
私有int-getUniqueCellId(字符c,int-i){
返回整数值(c)*10369+i;
}
}
以下是布局xml:

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent">
    <ScrollView
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:orientation="vertical">
        <RelativeLayout
             android:id="@+id/relativeLayout"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent">
        </RelativeLayout>
    </ScrollView>
</HorizontalScrollView>

我不明白,为什么第一排坏了,第五排坏了,我怎么能把它修好。。。如果可以的话,请帮助我,谢谢


Edit1:我没有提到我希望以编程方式进行编辑2:我更改了链接,我希望它对每个人都适用

我建议您为此使用XML布局文件。设置内容,使其正确布局,然后连接非布局的内容,如单击处理程序或稍后更改文本。

请用代码附加图像不要发送链接我无法查看其访问权限被拒绝设置重力在第一行编辑文本的左侧,然后重试。我更改了链接,设置重力不起作用这不是好答案,因为我必须以友好的方式生成UI,但这是唯一的答案,所以我接受它。我解决了