是否可以通过编程方式更改 View 外观顺序?
例子。
<EditText
android:id="@+id/edit_txt_address_location_street"
android:layout_width="0dip"
android:layout_height="36dp"
android:layout_marginBottom="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="8dp"
android:layout_weight="8"
android:background="@drawable/shape_edit_text"
android:inputType="textNoSuggestions"
android:textColor="@color/black"
android:textCursorDrawable="@null" />
<EditText
android:id="@+id/edit_txt_address_location_street_nr"
android:layout_width="0dip"
android:layout_height="36dp"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="8dp"
android:layout_weight="2"
android:background="@drawable/shape_edit_text"
android:inputType="textNoSuggestions"
android:textColor="@color/black"
android:textCursorDrawable="@null" />
关于显示正常外观顺序的xml。
1. edit_txt_address_location_street
2. edit_txt_address_location_street_nr
对于某些情况,我必须以编程方式反转外观顺序。 例如:
1. edit_txt_address_location_street_nr
2. edit_txt_address_location_street
最佳答案
大多数(如果不是全部的话)xml 命令都有其相应的编程调用。假设您的意思是“更改”是在用 xml 膨胀后添加或删除 View ,那么答案是肯定的,但这并不意味着您应该这样做。
如果您想动态添加/删除 View ,最好动态创建整个布局。相信我,一旦您知道如何操作,与 xml 布局相比并不难。我读过一些地方,如果你混合使用 xml 和动态布局可能会出现一些问题,我无法证明这一说法,但我所做的是用 xml 膨胀一个空的 linearlayout,然后动态添加所有 View 我要。
关于java - Android:可以通过编程方式更改 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17047274/