How to show / hide ImageView in FrameLayout - java

Im trying to show / hide a specifically ImageView, that it's inside a FrameLayout. At the same time, im gonna hide or show (on the contrary to ImageView), the LinearLayout with id recents_linear_layout
<com.android.systemui.recent.RecentsPanelView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recents_root"
android:layout_height="match_parent"
android:layout_width="match_parent">
<FrameLayout
android:id="#+id/recents_bg_protect"
android:background="#drawable/status_bar_recents_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:clipToPadding="false"
android:clipChildren="false">
<com.android.systemui.recent.RecentsHorizontalScrollView android:id="#+id/recents_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="#dimen/status_bar_recents_right_glow_margin"
android:divider="#null"
android:stackFromBottom="true"
android:fadingEdge="horizontal"
android:scrollbars="none"
android:fadingEdgeLength="#dimen/status_bar_recents_fading_edge_length"
android:layout_gravity="bottom|left"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false">
<LinearLayout android:id="#+id/recents_linear_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false">
</LinearLayout>
</com.android.systemui.recent.RecentsHorizontalScrollView>
**<ImageView android:id="#+id/landscape"
android:gravity="center"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0.0dip"
android:src="#drawable/landscape_img"
android:visibility="gone" />**
</FrameLayout>
<include layout="#layout/status_bar_no_recent_apps"
android:id="#+id/recents_no_apps"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
</com.android.systemui.recent.RecentsPanelView>
My java code, throws a NullPointerException, because it cant find the ImageView (because this is being executed on com.android.systemui.recent.RecentsHorizontalScrollView. This is the code
mLinearLayout = (LinearLayout) findViewById(R.id.recents_linear_layout);
mLinearLayout.setVisibility(mRecent ? LinearLayout.GONE : LinearLayout.VISIBLE);
mLandScape = (ImageView) findViewById(R.id.landscape);
mLandScape.setVisibility(mRecent ? View.VISIBLE : View.GONE);
Thanks in advance.

you could use ((Activity)getContext()).findViewById(R.id.landscape) though you should avoid it since there is no guarantee that the context is an activity. I can't understand why you are trying to hide some views inside this view. I think this is the activity's responsibility. You should make some interface with call back method to notify the activity about your event then let it hide the image view.

FIXED
Fix was making a external layout container with old Layout and ImageView as childs
<com.android.systemui.recent.RecentsHorizontalScrollView android:id="#+id/recents_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="#dimen/status_bar_recents_right_glow_margin"
android:divider="#null"
android:stackFromBottom="true"
android:fadingEdge="horizontal"
android:scrollbars="none"
android:fadingEdgeLength="#dimen/status_bar_recents_fading_edge_length"
android:layout_gravity="bottom|left"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false">
<LinearLayout android:id="#+id/child_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false">
<LinearLayout android:id="#+id/recents_linear_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false" />
<ImageView android:id="#+id/sense_landscape"
android:gravity="center"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0.0dip"
android:src="#drawable/sense_landscape"
android:visibility="visible" />
</LinearLayout>
</com.android.systemui.recent.RecentsHorizontalScrollView>

Related

NestedScrollView no longer working as soon as I add SwipeRefreshLayout

I noticed a strange behaviour in my application.
My scrollview contains two elements.
a SearchView
a RecyclerView
Those are wrapped by an LinearLayout.
Now I want to add a SwipeRefreshLayout to refresh the data containing in the RecyclerView.
As soon as I do that the ScrollView ignores the SearchView and only scrolls through the RecyclerView.
Here is the XML:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<SearchView
android:id="#+id/search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:iconifiedByDefault="false"
android:layout_marginTop="45dp"
android:queryHint="Search Here" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/listRV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
It should scroll the SearchView and the RecyclerView at the same time.
Why does it stop working as soon as I add a SwipeRefreshLayout and how can I fix that?
I solve this issue by wrapping the NestedScrollView inside of the SwipeRefreshLayout.
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<SearchView
android:id="#+id/search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:iconifiedByDefault="false"
android:queryHint="Search Here" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/listRV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

Android - LinearLayout not scrolling inside ScrollVIew

I have the problem with LinearLayout not being scrollable inside the ScrollView, instead it just appears to go beyond the screen frame (look closely at the bottom of the screenshot linked below).
I have the following structure in my XML layout:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.TextInputLayout>
<!-- More TextInputLayouts -->
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src = "#drawable/ic_done"
android:tint = "#color/white"/>
</android.support.design.widget.CoordinatorLayout>
No solutions found were able to fix the problem: I tried fillViewPort="true" and it didn't do it for me, I also tried commenting CoordinatorLayout - same result, layout_heights seem to be set properly as well.
Moreover, I tried to adjust LinearLayout's height progrmatically, what didn't help just as well.
I'm stuck with this problem for a while now and would really appreciate any help in this regard :)
Screenshot
It works for me with the XML below. I didn't change much, just added an orientation to the LinearLayout and some margin and awful background colors so you can see which view is moving and which is fixed while you scroll.
When you drag up and down, the teal box (the LinearLayout) moves up and down as expected within the red box (the ScrollView). If your LinearLayout is taller than the screen, it will go off the bottom, that's the point of the ScrollView.
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:background="#ff0000"
android:scrollbars="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_margin="16dp"
android:background="#008080"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
you put linear layout orientation in xml code
like..
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
or
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
Try this:-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/whiteColor"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<!-- vertical ScrollView to make all the items or views scrollable -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<!-- LinearLayout Inside ScrollView -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- create a Linear Layout with horizontal orientation and weightSum property -->
<LinearLayout
android:id="#+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="2">
<EditText
android:id="#+id/lastName"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_weight="1.4"
android:background="#color/editTextBack"
android:hint="Last Name"
android:imeOptions="actionNext"
android:paddingLeft="10dp"
android:singleLine="true"
android:textColor="#color/blackColor" />
</LinearLayout>
<!-- create a Linear Layout with horizontal orientation and weightSum property -->
<LinearLayout
android:id="#+id/thirdLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="2">
<!-- place one TextView and one EditText inside layout using weight property -->
<TextView
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginRight="10dp"
android:layout_weight="0.6"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Address"
android:textColor="#color/blackColor" />
</LinearLayout>
</ScrollView>
</LinearLayout>

RecyclerView height wrap_content doesn't work in NestedScrollView

So I have recyclerView with height wrap_content as I understand this means that recyclerView should expand and collapse whenever I add items to it or remove, but for some reason in NestedScrollView it doesn't behave like that when I add new Objects to it, it stays same size as it was any ideas what could be wrong?
Tried adding
android:fillViewport="true"
But no reactions as far as I understand it could be because RecyclerView not getting updated when children of it changes, because when I restart app it collapses or expands to proper size.
Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/icons"
android:orientation="vertical">
<LinearLayout
android:id="#+id/main_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical">
<include layout="#layout/toolbar" />
<android.support.v4.widget.NestedScrollView
android:id="#+id/nested"
android:fillViewport="true"
android:scrollbars="none"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/empty_group_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TextView
android:id="#+id/empty_text_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="#string/no_group_first"
android:textColor="#color/secondary_text"
android:textSize="17sp" />
<ImageView
android:id="#+id/add_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/empty_text_first"
android:src="#drawable/ic_add_group_gry" />
<TextView
android:id="#+id/empty_text_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/add_icon"
android:text="#string/no_group_second"
android:textColor="#color/secondary_text"
android:textSize="17sp" />
</RelativeLayout>
</RelativeLayout>
<TextView
android:textSize="14sp"
android:layout_marginStart="6dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Favorite groups"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/favorite_group_list"
android:nestedScrollingEnabled="true"
android:layout_width="match_parent"
android:layout_height="156dp"
android:layout_gravity="center"
android:background="#color/icons"
android:padding="6dp">
</android.support.v7.widget.RecyclerView>
<TextView
android:textSize="14sp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_marginStart="6dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Groups"/>
<android.support.v7.widget.RecyclerView
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/group_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/background"
android:nestedScrollingEnabled="false"
android:padding="6dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/add_new_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="#drawable/ic_playlist_add_48px"
app:behavior_autoHide="true"
app:layout_anchor="#id/main_holder"
app:layout_anchorGravity="bottom|right|end" />
Hi kosas give wrap _content for recycler view and while setting layout
manager follow this
linearLayoutManager = new LinearLayoutManager(getActivity()) {
#Override
public boolean canScrollVertically() {
return false;
}
};
Probably the problem is related with the adapter's layout. Be sure to put some fixed value or wrap_content on the adapter's layout height. If it's match_parent it won't work as expected because each row will fill all the RecyclerView

Android add image on top of another imageView as image below in Layout XML

How to create a android Layout where you add a smaller imageView on Top of another Image View. but only half way as the image below.
Thank.
this is the sample I try but it does not work:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageCover"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/big_cover_img" />
<ImageView
android:id="#+id/imageProfile"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignBottom="#+id/imageCover"
android:layout_centerHorizontal="true"
android:src="#drawable/profile_pic" />
<!-- android:layout_alignBottom="#+id/imageCover" -->
</RelativeLayout>
Use FrameLayout as parent and LinearLayout as child with weight property :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:id="#+id/imageCover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/big_cover_img" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/imageProfile"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:src="#drawable/ic_launcher" />
</FrameLayout>
Set the second view to be below the first then set top margin of the bottom view to -50 dp or whatever value you want it to overlap

How to Set indicator on view pager?

i am trying to show the indicator on view pager such a way that indicator become in bottom of the image and align Center horizontal and center vertical I used Frame layout for this purpose but still not getting desired result.. i think i am missing any attribute my XML code is:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/baneer"
android:layout_width="fill_parent"
android:layout_height="140dp"
android:background="#000000"
android:orientation="vertical">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.ViewPager
android:id="#+id/myfivepanelpager"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#f6f7f9"
android:orientation="horizontal">
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/view_indicator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#android:color/transparent" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
Try this :
android:layout_alignParentBottom="true" instead of android:layout_gravity="bottom"

Categories

Resources