java - 隐藏特定时间的布局

标签 java android time timepicker

我正在构建 app.in,我想在上午 8 点到 12 点之间隐藏我的布局。我尝试使用线程和异步任务,但我不明白如何给出 8 到 12 之间的时间段。

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
     <de.hdodenhof.circleimageview.CircleImageView
            android:layout_width="40dp"
            android:layout_height="50dp"
            android:layout_marginLeft="3dp"
            android:scaleType="centerCrop"
            android:src="@drawable/vegitables"
            app:civ_border_color="#80000000"
            app:civ_border_width="1dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="5dp"
            android:text="Veg :"
            android:textColor="#F00"
            android:textSize="18sp"
            android:textStyle="bold" />
    </LinearLayout>

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="150dp"/>

</LinearLayout>

最佳答案

试试这个:

Calendar now = Calendar.getInstance();
int currentHour = now.get(Calendar.HOUR_OF_DAY);
if(currentHour >=7 && currentHour <= 11)
    rootLayoutReference.setVisibility(View.GONE);
else
    rootLayoutReference.setVisibility(View.VISIBLE);

关于java - 隐藏特定时间的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40632656/

相关文章:

java - android套接字连接更新图形

Android:在 attachBaseContext 中使用 DataStore

android - Parcelable 示例出错。

javascript - 如何确定 "X minutes from now"事件的日期

java - 如何对具有指定属性和排序顺序的列表进行排序

java - 使用简单的 spring memcached 进行 JSON 序列化

android - 获取根元素必须格式正确。 Android版本中的错误

javascript - 正确的时间显示

ios - swift : How can I get time in hours of my current location for my app?

java - restfb 获取自特定日期以来所有帖子的所有评论