您的位置:首页 > 编程语言

关于安卓XML布局里面的引用与代码顺序

2016-12-31 05:11 281 查看
我有一个问题

首先看这段伪代码

        <RelativeLayout>

            <Button android:id="@+id/toast_dialog_confirm"/>

            <Button

                android:id="@+id/toast_dialog_cancel"

                android:layout_toLeftOf="@+id/toast_dialog_confirm" />


        </RelativeLayout>

要实现的效果是【后面的一个Button放到前一个Btn的左边】

然后再看这段

        <RelativeLayout>

            <Button

                android:id="@+id/toast_dialog_cancel"

                android:layout_toLeftOf="@+id/toast_dialog_confirm" />

    <Button

                android:id="@+id/toast_dialog_confirm"/>


        </RelativeLayout>

确实以上两段都可以实现目标功能

但是第二段代码会不会有隐患,会不会因为XML的读取顺序出现“toast_dialog_confirm”找不到的情况

就是会不会出现那种【还未读取到这个Btn但已经引用了这个Btn的错误】

需要说明的是这两个Btn都已经写到了代码中
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐