2016-05-06 72 views
0

我正在嘗試爲android應用程序設計一個佈局。 這是XML:在android xml佈局中的微調框

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="New Text" 
    android:id="@+id/nameFB" 
    android:layout_gravity="end" /> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:gravity="end"> 

     <Spinner 

      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="end" 
      android:text="@string/type_string" /> 

     <EditText 
      android:layout_width="50dp" 
      android:layout_height="wrap_content" 
      android:inputType="textPersonName" 
      android:ems="10" 
      android:id="@+id/yearTextName" 
      android:background="@drawable/edit_text_style"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="end" 
      android:text="@string/year_string" /> 

     <EditText 
      android:layout_width="75dp" 
      android:layout_height="wrap_content" 
      android:inputType="textPersonName" 
      android:ems="10" 
      android:id="@+id/creatorTextName" 
      android:background="@drawable/edit_text_style"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="end" 
      android:text="@string/creator_string" /> 

     <EditText 
      android:layout_width="75dp" 
      android:layout_height="wrap_content" 
      android:inputType="textPersonName" 
      android:ems="10" 
      android:id="@+id/nameTextBox" 
      android:background="@drawable/edit_text_style"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="end" 
      android:text="@string/name_string" /> 


    </LinearLayout> 

    <ListView 
     android:id="@+id/lv_search_results" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    </ListView> 
</LinearLayout> 
</LinearLayout> 

,它看起來像這樣:

enter image description here

,但是當我添加一個ID值的微調:

<Spinner 
      android:id="@+id/a" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

由於某種原因,廢墟佈局:

enter image description here

有誰知道爲什麼會發生?我唯一改變的是一個id的值,而不是圖形。 我該如何解決它?或者我該如何重新排列xml,以便文本框和微調框可以用文本視圖(可能是兩行)顯示?我試圖逐個放置線性佈局,並將它們放在窗口小部件中,但每次看起來都像第二張圖。

回答

0

我仍在尋找這種行爲背後的原因。

但暫時,您可以使用下面的代碼爲您的佈局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Text" 
     android:id="@+id/nameFB"/> 


     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <Spinner 
       android:id="@+id/adsa" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:text="type" 
       android:layout_weight="1"/> 

      <EditText 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:inputType="textPersonName" 
       android:ems="10" 
       android:id="@+id/yearTextName" 
       android:layout_weight="1"/> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:text="year" 
       android:layout_weight="1"/> 

      <EditText 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:inputType="textPersonName" 
       android:ems="10" 
       android:id="@+id/creatorTextName" 
       android:layout_weight="1"/> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:text="craetor" 
       android:layout_weight="1"/> 

      <EditText 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:inputType="textPersonName" 
       android:ems="10" 
       android:id="@+id/nameTextBox" 
       android:layout_weight="1"/> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:text="name" 
       android:layout_weight="1"/> 

    </LinearLayout> 
    <ListView 
     android:id="@+id/lv_search_results" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    </ListView> 
</LinearLayout> 

您可以根據您的需要修改權重的觀點。

0

我強烈建議你在這種情況下你應該改變你的設計。微調器保持在一行,其餘的控制保持在第二行。