android - 将布局可见性设置为 GONE 时,看不到布局外部的微调器

标签 android android-layout

在我的 XML 中,我有一个“选择运算符(operator)”微调器,然后是一个包含一些编辑文本的线性布局,还有一个“选择区域”微调器。

在布局下方我有一个编辑文本和一个按钮。 在按钮上单击甚至我将布局的可见性设置为 GONE 或 VISIBLE。

当我将可见性设置为 GONE 时,我可以看到“选择运算符(operator)”微调器,但是当我将可见性设置为 VISIBLE 时,我看不到我的微调器。我不知道为什么会这样。

谁能告诉我问题到底出在哪里

我的 XML:

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

    <ScrollView
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:fillViewport="true">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_gravity="center">


        <Spinner
            android:id="@+id/splayout_electricity_OPERATORsp"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:textSize="10dp"
            android:layout_marginTop="40dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:entries="@array/operators_electricity"/>



        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_marginTop="20dp"

            android:id="@+id/llayout_electricity_TNEBLAYOUTl"
            android:visibility="visible">

            <Spinner
                android:id="@+id/splayout_electricity_TNEBREGIONsp"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:textSize="10dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:gravity="left"
                android:entries="@array/operators_electricity_REGION"/>

            <EditText
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:textSize="15dp"
                android:layout_marginTop="20dp"
                android:hint="Code"
                android:gravity="left"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:id="@+id/elayout_electricity_TNEBCODEet" />

            <EditText
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:textSize="15dp"
                android:layout_marginTop="20dp"
                android:hint="Consumer Name"
                android:gravity="left"
                android:layout_marginLeft="20dp"
                android:inputType="textPersonName"
                android:layout_marginRight="20dp"
                android:id="@+id/elayout_electricity_TNEBCONSUMERNAMEet" />

            <EditText
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:textSize="15dp"
                android:layout_marginTop="20dp"
                android:hint="Contact Number"
                android:inputType="numberDecimal"
                android:gravity="left"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:id="@+id/elayout_electricity_TNEBCONTACTNOet" />

        </LinearLayout>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:textSize="15dp"
            android:layout_marginTop="20dp"
            android:hint="Consumer Number (Refer Bill)"
            android:gravity="left"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:id="@+id/elayout_electricity_CONSUMERNOet" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:textSize="15dp"
            android:layout_marginTop="20dp"
            android:hint="Amount"
            android:gravity="left"
            android:inputType="numberDecimal"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:id="@+id/elayout_electricity_AMOUNTet" />

        <Button
            android:id="@+id/blayout_electricity_RECHARGEbt"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_marginTop="30dp"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:background="#16562e2e"
            android:textStyle="bold"
            android:text="Pay Bill"
            android:textColor="#000000"
            android:textSize="15dp"/>

    </LinearLayout>

    </ScrollView>
</FrameLayout>





My Java file:

    l_TNEB = (LinearLayout) getActivity().findViewById(R.id.llayout_electricity_TNEBLAYOUTl);
        b_paybill = (Button) getActivity().findViewById(R.id.blayout_electricity_RECHARGEbt);

        b_paybill.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(l_TNEB.getVisibility()== View.VISIBLE)
                {
                    l_TNEB.setVisibility(View.GONE);
                }else {
                    l_TNEB.setVisibility(View.VISIBLE);
                }
            }
        });

Can see the Operator Spinner

Where is my spinner

最佳答案

将 layout_height 更改为 wrap_content

 <ScrollView
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:fillViewport="true">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="center">

关于android - 将布局可见性设置为 GONE 时,看不到布局外部的微调器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34014243/

相关文章:

java - 确定服务实例是否正在运行并终止它

android - adjustResize 不适用于 CoordinatorLayout

android - 是否可以更改 Android 工具栏的默认矩形形状?

android - 将数据传递给服务器并接收它

android - Jacoco java.lang.instrument.IllegalClassFormatException : Error while instrumenting Class

android - 如何在 string.replace() 方法中设置值?

java - 导航菜单 fragment 无法初始化其布局的组件

Android-Studio 数据绑定(bind)不起作用

android - setImageBitmap 不显示

android - 将底部导航 View 实现到 fragment 中