2016-05-06 6 views
0

Ich versuche, ein Layout für eine Android-App zu entwerfen. dies ist das xml:Spinner in android XML-Layout

<?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> 

und es sieht wie folgt aus:

enter image description here

aber wenn ich hinzufügen, einen ID-Wert für den Spinner:

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

aus irgendeinem es Grund ruiniert das Layout:

enter image description here

Weiß jemand, warum passiert das? Die einzige Sache, die ich verändere, ist ein Wert einer ID, nicht etwas Grafik. Wie kann ich es beheben? Oder wie kann ich das XML neu anordnen, so dass die Textfelder und der Drehfeld mit den Textansichten sichtbar sind (möglicherweise in zwei Reihen)? Ich habe versucht, eines nach dem anderen linear anzuordnen und die Widgets einzubauen, aber jedes Mal sieht es wie das zweite Bild aus.

Antwort

0

Ich bin immer noch auf der Suche nach dem Grund für dieses Verhalten.

Aber für den Augenblick, können Sie unter Code für das Layout verwenden:

<?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> 

Sie können die Gewichte für Ansichten nach Ihrem Bedarf ändern.

0

Ich empfehle Ihnen in dieser Situation, Sie sollten Ihr Design ändern. Spinner in einer Reihe und Rest der Kontrolle in der zweiten Reihe.