我是Android開發新手,目前很喜歡它。XML屬性及其對應的相關方法
我一直在使用XML文件構建用戶界面,發現構建靜態用戶界面非常容易。
現在,我需要構建一個UI,其中一個TextView位置在運行時發生更改。
這隻能使用XML來完成嗎?現在
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_height="wrap_content"
android:text="0%"
android:layout_width="wrap_content"
android:id="@+id/percent"
android:textSize="15sp"
android:layout_x="41dip"
android:layout_y="295dip">
</TextView>
</AbsoluteLayout>
我可以通過改變layout_x
和layout_y
價值的任何位置TextView的。但是如何在運行時做到這一點?
我已經試過這樣:
TextView text;
text=(TextView)findViewById(R.id.percent);
做text.setText("This can be done");
會輕易改變在運行時的文本,但我怎麼可以改變從代碼現在的位置?