我知道有一些关于这个问题的问题,但是所有这些问题都使用了动画。在我的活动中,我根本没有任何动画。我有一个默认可见并且根据我在闪屏界面中获取的功能标志设置为隐藏的TextView。
这是我的xml文件:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/profile_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/profile_bg"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingTop="?android:actionBarSize">
<TextView
android:id="@+id/payments_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:background="@drawable/profile_payment_bg"
android:clickable="true"
android:drawableLeft="@drawable/ic_profile_payment"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:onClick="onClick"
android:padding="8dp"
android:text="Payment"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="@android:color/white" />
...
</LinearLayout>
</FrameLayout>
虽然我已将Clickable和OnClickListener的功能设置为false和null,但即使我的付款按钮不可见,OnClick()功能也会被调用 :(
@Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_profile);
this.mPayments = (TextView) findViewById(R.id.payments_btn);
// Check if payment functionality available for the Passenger
final PassengerFeatureResponse cachedFeature = FeatureResponse.fromJsonString(PreferenceUtils.getFeatureResponse(this));
if (cachedFeature == null || !cachedFeature.isMade())
{
this.mPayments.setVisibility(View.GONE);
this.mPayments.setClickable(false);
this.mPayments.setOnClickListener(null);
}
}
我甚至试图从XML文件将可见性设置为Gone,然后从代码中将其设置为可见,但功能仍然相同 :(
这可能是因为我已经在XML文件中定义了onClick功能,如果我从代码中设置点击监听器,我的问题就会解决,但是,我希望以这种方式修复该问题。
任何建议将不胜感激。谢谢。
mPayments.setVisibility(View.GONE);
足够了,它肯定能起作用。 - Neal Ahluvalia