Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android的设计窗口中未显示下拉列表(微调器)_Android_Android Layout_Android Studio - Fatal编程技术网

android的设计窗口中未显示下拉列表(微调器)

android的设计窗口中未显示下拉列表(微调器),android,android-layout,android-studio,Android,Android Layout,Android Studio,我是android的初学者。我有一个问题,为什么微调器没有显示在设计窗口中?。为了您的帮助,我在下面添加了一个代码 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Text View!" android:paddingRight="100dp" app:layout_constraintBottom_toB

我是android的初学者。我有一个问题,为什么微调器没有显示在设计窗口中?。为了您的帮助,我在下面添加了一个代码

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Text View!"
    android:paddingRight="100dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:id="@+id/brand"


    />


<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:layout_below="@+id/color"
    android:layout_alignLeft="@+id/color"
    android:id="@+id/find_beer"

    />

<Spinner
    android:id="@+id/color"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="72dp"
    >
</Spinner>


您使用的
约束不正确。按如下方式更改布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <Spinner
        android:id="@+id/color"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"></Spinner>

    <Button
        android:id="@+id/find_beer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"    
        app:layout_constraintBottom_toBottomOf="@+id/color"
        app:layout_constraintStart_toEndOf="@+id/color"
        app:layout_constraintTop_toBottomOf="@+id/color" />

    <TextView
        android:id="@+id/brand"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="57dp"
        android:layout_marginRight="57dp"
        android:paddingRight="100dp"
        android:text="Text View!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />  

</android.support.constraint.ConstraintLayout>
表示以下内容:

视图的大小应仅足以包含其内容


即使您更正了约束,也要记住向微调器添加一些内容,否则您只会看到屏幕上的下拉箭头。

在使用java代码或使用资源的xml设置值后,更改布局类型,就像使用方向垂直的线性布局或相对布局设置布局一样

<resources>
<string-array name="planets_array">
    <item>Mercury</item>
    <item>Venus</item>
    <item>Earth</item>
    <item>Mars</item>
    <item>Jupiter</item>
    <item>Saturn</item>
    <item>Uranus</item>
    <item>Neptune</item>
</string-array>
XML代码

<Spinner
                        android:id="@+id/spCountry"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginLeft="25dp"
                        android:layout_centerVertical="true"
                        android:layout_gravity="center"
                        android:background="@android:color/transparent"
                        android:gravity="center"
                        android:spinnerMode="dropdown" />

活动代码

Spinner spCountry;

spRole = (Spinner)getView().findViewById(R.id.spCountry);

String[] arRoleSpinner = {"India","USA","NWZ","SA", "WI","ENG"};
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item, arRoleSpinner);
        adapter.setDropDownViewResource(R.layout.spinner_item);
        spRole.setAdapter(adapter);

        spRole.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                ((TextView) adapterView.getChildAt(0)).setTextColor(Color.WHITE);
                ((TextView) adapterView.getChildAt(0)).setTextSize(12);


            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
Spinner-spCountry;
spRole=(微调器)getView().findviewbyd(R.id.spCountry);
字符串[]arRoleSpinner={“印度”、“美国”、“NWZ”、“SA”、“WI”、“英语”};
ArrayAdapter=新的ArrayAdapter(getActivity(),android.R.layout.simple\u微调器\u项,arRoleSpinner);
adapter.setDropDownViewResource(R.layout.spinner\u项);
spRole.setAdapter(适配器);
spRole.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView AdapterView、View视图、int i、long l){
((TextView)adapterView.getChildAt(0)).setTextColor(Color.WHITE);
((TextView)adapterView.getChildAt(0)).setTextSize(12);
}
@凌驾
未选择公共无效(AdapterView AdapterView){
}
});
使用此代码

<Spinner
android:id="@+id/color"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="72dp" ></Spinner>

因为在spinner(下拉列表)中,我们在运行时添加了项(在java代码中),所以在运行应用程序时会显示出来。java代码中的每一个变化,如颜色变化、可见性等,在我们运行应用程序时都会显示出来


也可以访问此

发布整个布局XML文件。@Ankesh content\u find\u beer.XML是Spinner android:id=“@+id/color”android:layout\u width=“wrap\u content”android:layout\u height=“wrap\u content”android:layou alignParentTop=“true”android:layout\u centerHorizontal=“true”android:layout\u marginTop=“37dp”>String.xml是BeerAdvisor设置和内容\u find\u beer.xml,我已经在qstnNo中添加了,代码不起作用。整个代码是“xmlns:app=”“xmlns:tools=”“android:layout\u width=“match\u parent”android:layout\u height=“match\u parent”app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”tools:context=“.FindBeerActivity”tools:showIn=“@layout/activity\u find\u”“>删除您的整个代码,并用我粘贴的内容替换它,然后检查是否工作正常!记住点击勾号将其标记为已接受,这样其他人也可以从中受益。享受编码Java Point是一个很好的解决方案。但告诉我一件事,按钮和文本显示在设计窗口上,下拉列表不会出现。因为在spinner(下拉列表)中,我们在运行时(java代码)添加项目,所以在运行应用程序时会显示出来。而且java代码中的每一个变化,比如颜色变化、可见性等,都会在我们运行app.thnaxx时显示出来,所以这就是这个过程背后的原因。再次感谢您。请告诉我,如果不在“活动”中添加代码,是否无法在“设计”窗口上显示下拉列表?我同意该功能不起作用。对于exp,该按钮不会执行任何任务,但会在设计窗口中显示其外观。类似地,如果我只有微调器,并且什么也不做,它必须显示在设计窗口上。请告诉我,我只想看到下拉列表,不想执行任何任务。不在java文件中添加代码是不可能的吗
<Spinner
                        android:id="@+id/spCountry"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginLeft="25dp"
                        android:layout_centerVertical="true"
                        android:layout_gravity="center"
                        android:background="@android:color/transparent"
                        android:gravity="center"
                        android:spinnerMode="dropdown" />
Spinner spCountry;

spRole = (Spinner)getView().findViewById(R.id.spCountry);

String[] arRoleSpinner = {"India","USA","NWZ","SA", "WI","ENG"};
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item, arRoleSpinner);
        adapter.setDropDownViewResource(R.layout.spinner_item);
        spRole.setAdapter(adapter);

        spRole.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                ((TextView) adapterView.getChildAt(0)).setTextColor(Color.WHITE);
                ((TextView) adapterView.getChildAt(0)).setTextSize(12);


            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
<Spinner
android:id="@+id/color"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="72dp" ></Spinner>