[英]spinner in android xml layout
I'm trying to design a layout for an android app. 我正在尝试为Android应用程序设计布局。 this is the xml:
这是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>
and it looks like this: 它看起来像这样:
but when I add an id value for the spinner: 但是当我为微调器添加ID值时:
<Spinner
android:id="@+id/a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
for some reason it ruins the layout: 由于某种原因,它破坏了布局:
Does anyone know why does it happen? 有谁知道为什么会这样? The only thing I'm changing is a value of an id, not something graphic.
我唯一要更改的是id的值,而不是图形的值。 How can I fix it?
我该如何解决? Or how can I rearrange the xml so that the text boxes and the spinner will be visible with the text views (maybe in two rows)?
或者如何重新排列xml,以使文本框和微调框在文本视图中可见(也许分两行)? I tried to put to linear layout one after the other and put in them the widgets, but every time it looks like the second picture.
我试图一个接一个地放置线性布局,然后将小部件放入其中,但是每次看起来就像第二张图片一样。
I am still searching the reason behind this behavior. 我仍在寻找这种行为背后的原因。
But for the time being , you can use below code for your 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"/>
<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>
You can modify the weights for views according to your need. 您可以根据需要修改视图的权重。
I highly recommend you in this situation you should change your design. 在这种情况下,我强烈建议您更改设计。 Spinner keep in a single row and rest of the control keep in second row.
微调框保持在单行中,其余控件保持在第二行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.