在我的 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);
}
}
});
最佳答案
将 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/