我有一个布局需要显示,但目前无法正常工作。我想要显示的布局的id为“goal_reminder”,在xml中可见度被设置为“GONE”。
以下是xml代码:
<?xml version="1.0" encoding="utf-8"?>
<com.View.pages.ActivityPage
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/activity_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/activitylist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e7e6ee"
android:clipToPadding="false"
android:divider="@null"
android:paddingBottom="80dp" />
</android.support.v4.widget.SwipeRefreshLayout>
<RelativeLayout
android:id="@+id/goal_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/transparent_color"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="match_parent"
android:layout_height="145dp"
android:src="@drawable/sunsetforgoal" />
<ImageView
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/goal_reminder_title"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="35dp"
android:src="@drawable/logo" />
<TextView
android:id="@+id/goal_reminder_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="No goal in progress"
android:textColor="@color/text_color"
android:textSize="26sp" />
<TextView
android:id="@+id/goal_reminder_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/goal_reminder_title"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="Create a new goal in your \nprofile."
android:textColor="@color/text_color"
android:textSize="18sp" />
</RelativeLayout>
<TextView
android:id="@+id/playground_welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:autoLink="all"
android:gravity="center_horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/welcome_string"
android:textSize="18sp"
android:visibility="gone" />
</com.View.pages.ActivityPage>
这里是onFinishInflate(我正在使用Screenplay/Flow库,因此它代替了onCreate)。你可以看到我试图设置goalReminderLayout.setVisibility(View.Visible),但实际上并没有使其可见。我已经在if语句之外测试过相同的代码行,它能够正常工作。我还测试过确保它在if语句中达到了那一行,并且那部分也很好用,lastTriggerDate已经成功保存在Parse中。我不明白为什么它在onFinishInflate之外的if语句中能够正常工作。我还使用了Log.d("TestVisiblity", goalReminderLayout.getVisibility()); 进行了测试,它返回了0(可见),所以似乎它是可见的,但它实际上没有显示在我的屏幕上。
Date lastTriggerDate = new Date();
Boolean noDateInParse = false;
if (currentUser.getLastTriggerDate() != null) {
lastTriggerDate = currentUser.getLastTriggerDate();
} else {
noDateInParse = true;
}
Boolean inToday = DateUtils.isToday(lastTriggerDate.getTime());
if (!inToday) {
currentUser.setLastTriggerDate(currentTime);
currentUser.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
goalReminderLayout.setVisibility(View.VISIBLE);
fireGoalReminderAlert();
} else {
e.printStackTrace();
}
}
});
} else if (noDateInParse) {
currentUser.setLastTriggerDate(currentTime);
currentUser.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
goalReminderLayout.setVisibility(View.VISIBLE);
fireGoalReminderAlert();
} else {
e.printStackTrace();
}
}
});
}
以下是fireGoalReminderAlert()的代码。它仅被设置为在10秒后将可见性设置回"gone"。我在测试时注释掉了这行代码,但还是没有成功,所以我认为这不是问题的原因。
public void fireGoalReminderAlert() {
Runnable mRunnable;
Handler mHandler = new Handler();
mRunnable = new Runnable() {
@Override
public void run() {
goalReminderLayout.setVisibility(View.GONE);
}
};
mHandler.postDelayed(mRunnable, 10 * 1000);
}
fireGoalReminderAlert()
里面写了什么? - Shadab Ansari