2011-12-27 63 views
0

對於xml行: android:layout_width="fill_parent",是否有像fill_parent/2這樣的常量值?我希望我的對象只填充屏幕的一半,而不是全部。在xml中創建一個寬度和高度爲屏幕一半的對象

+0

可能會使用layout_weight屬性 – 2011-12-27 06:05:28

+0

給出您的xml佈局文件。 – 2011-12-27 06:41:00

+0

<?xml version =「1.0」encoding =「utf-8」?> Someonation 2011-12-27 06:43:28

回答

2

可以爲此目的使用線性佈局的「權重」。例如如果要在兩個控件之間劃分可用空間:

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <EditText 
      android:layout_height="wrap_content" 
      android:layout_width="0dp" 
      android:layout_weight="1.0"/> 
     <EditText 
      android:layout_height="wrap_content" 
      android:layout_width="0dp" 
      android:layout_weight="1.0"/> 
</LinearLayout> 
1

按比例尺寸使用Layout_weight LinearLayout的方法。 爲你的情況

<Linearlayout weight_sum=2> 
    <yourView layout_weight=1 /> 
</Linearlayout> 

//須藤語法

+0

我不使用佈局,我的代碼是用於列表視圖,並且我是通過android.com教程說只使用TextView創建一個xml文件 – Someonation 2011-12-27 06:11:53

+0

hmmmmmmm ........似乎你正在使用arrayAdapter而不是自定義的適配器。不用擔心,只需通過R.layout.name和R.id.textviewid即可。爲更多的幫助粘貼代碼snippate – 2011-12-27 06:51:17

+0

好的,所以我切換R.layout.name與R.layout.TextViewID ...然後什麼?...如果我想告訴你我的代碼,我該怎麼做?我無法從格式幫助中瞭解如何製作塊來發布代碼 – Someonation 2011-12-27 06:59:54