Reputation: 635
this is my layout code
<?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">
<LinearLayout
android:id="@+id/reveal_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:baselineAligned="true"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageButton
android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="140dp"
android:background="@drawable/logo" />
</LinearLayout>
</LinearLayout>
<!-- -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="136dp"
android:layout_margin="5dp"
android:gravity="center"
android:orientation="horizontal"
android:layout_weight="0.77">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageButton
android:id="@+id/res"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/response" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="response" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageButton
android:id="@+id/profile"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/profile" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="my profile" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:layout_margin="10dp">
<TextView
android:id="@+id/badge_notification_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/ic_notification_overlay"
android:text="27"
android:textColor="#FFF"
android:textSize="12sp"
android:textStyle="bold"
android:layout_above="@id/noti"
android:layout_marginLeft="20dp" />
<ImageButton
android:id="@+id/noti"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/notification" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Notification" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageButton
android:id="@+id/req"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/req" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="add request" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageButton
android:id="@+id/logout"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/logout" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="logout" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageButton
android:id="@+id/help"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/help" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="help" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
and this the screenshot of result
the badge code its
<TextView
android:id="@+id/badge_notification_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/ic_notification_overlay"
android:text="27"
android:textColor="#FFF"
android:textSize="12sp"
android:textStyle="bold"
android:layout_above="@id/noti"
android:layout_marginLeft="20dp" />
i add badge to the notification but its make notification icon and text of notification not in one line with other table did there are some thing to make badge relative and i can add it any where on xml code without change the other item position so now the problem this badge will set visible to false when its zero so the notification icon will go little above and when new notification come and set visible true the notification icon will back down
Upvotes: 0
Views: 195
Reputation: 675
You can achieve that by setting the visibility to INVISIBLE, not to GONE
according to Google documentation, Set visibility: You can hide or show views using setVisibility(int).
If you set it to INVISIBLE This view is invisible, but it still takes up space for layout purposes.
If you set it to GONE This view is invisible, and it doesn't take any space for layout purposes.
Upvotes: 1