我有一个布局,我正试图使其可见,但它目前无法正常工作。我想要显示的布局在下面具有 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 秒后将可见性设置回消失。我在测试时注释掉了这一行,但仍然没有成功,所以我认为这不是导致问题的原因。
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);
}
最佳答案
当您将布局设置为从消失变为可见时,最好使 View 无效以允许在布局上重绘。
goalReminderLayout.setVisibility(View.VISIBLE);
goalReminderLayout.invalidate();
查看 android 文档以获取更多信息
http://developer.android.com/reference/android/view/View.html
关于java - Android setVisibility(View.Visible)不适用于布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37169847/
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我已经在Sinatra上创建了应用程序,它代表了一个简单的API。我想在生产和开发上进行部署。我想在部署时选择,是开发还是生产,一些方法的逻辑应该改变,这取决于部署类型。是否有任何想法,如何完成以及解决此问题的一些示例。例子:我有代码get'/api/test'doreturn"Itisdev"end但是在部署到生产环境之后我想在运行/api/test之后看到ItisPROD如何实现? 最佳答案 根据SinatraDocumentation:EnvironmentscanbesetthroughtheRACK_ENVenvironm
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
是否可以为特定(或所有)项目使用多个布局?例如,我有几个项目,我想对其应用两种不同的布局。一个是绿色的,一个是蓝色的(但是)。我想将它们编译到我的输出目录中的两个不同文件夹中(例如v1和v2)。我一直在玩弄规则和编译block,但我不知道这是怎么回事。因为,每个项目在编译过程中只编译一次,我不能告诉nanoc第一次用layout1编译,第二次用layout2编译。我试过这样的东西,但它导致输出文件损坏。compile'*'doifitem.binary?#don’tfilterbinaryitemselsefilter:erblayout'layout1'layout'layout2'
当我使用has_one时,它工作得很好,但在has_many上却不行。在这里您可以看到object_id不同,因为它运行了另一个SQL来再次获取它。ruby-1.9.2-p290:001>e=Employee.create(name:'rafael',active:false)ruby-1.9.2-p290:002>b=Badge.create(number:1,employee:e)ruby-1.9.2-p290:003>a=Address.create(street:"123MarketSt",city:"SanDiego",employee:e)ruby-1.9.2-p290