假設我有一個tablerow,並且在那個tablerow裏面有3個元素(ImageViews)。Android元素固定位置
在第一種情況下,所有3個項目都具有可見性值VISIBLE。假設正在將元素的可見性設置爲GONE。那麼在這種情況下,其他兩件物品會被調整到錯過一次的地方。
但我想要的是我需要成爲一個固定位置的所有項目。因此,如果我將任何項目的可見性都設爲GONE狀態,那麼在這種情況下,其餘元素也會處於同一個位置。
任何人都可以幫助我做到這一點。
假設我有一個tablerow,並且在那個tablerow裏面有3個元素(ImageViews)。Android元素固定位置
在第一種情況下,所有3個項目都具有可見性值VISIBLE。假設正在將元素的可見性設置爲GONE。那麼在這種情況下,其他兩件物品會被調整到錯過一次的地方。
但我想要的是我需要成爲一個固定位置的所有項目。因此,如果我將任何項目的可見性都設爲GONE狀態,那麼在這種情況下,其餘元素也會處於同一個位置。
任何人都可以幫助我做到這一點。
使用stretchcolumns
佈局,並在每ImageView
指定layout_span
和layout_column
..
Try this out,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1" >
<TableRow
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/topbg" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_span="1"
android:src="@drawable/ic_add" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_span="1"
android:src="@drawable/ic_add" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_span="1"
android:src="@drawable/ic_add" />
</TableRow>
</TableLayout>
</LinearLayout>
我想你沒有明白我的意思。在這種情況下,同樣的事情也會發生。 – 2012-02-16 14:46:16
如果你想要更多的靈活性,您的項目總是試圖去相對佈局,希望你能輕鬆解決您的問題通過使用相對佈局。你可以動態地或靜態地對物品做任何你想做的事情。
你可以更具體..或你可以只提供任何有用的鏈接。 – 2012-02-16 11:33:50