View doesn't reappear after setVisibility(View.GONE) - android

I have a LinearLayout which I'm trying to make VISIBLE, then GONE, then VISIBLE again. However after making it GONE, it doesn't become visible again. As a note, it works fine if I make it INVISIBLE: it appears and disappears with no problem.
These are my files:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/noconnectionll"
android:visibility="gone"
android:padding="#dimen/node_default_spacing"
android:background="#color/category_no_internet"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="#string/no_internet_short"
android:textColor="#fff"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/no_connection_retry"
android:text="#string/try_again"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ListView
android:dividerHeight="0dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="#+id/spinner_wrapper"
tools:visibility="visible"
android:visibility="invisible"
android:background="#a0ffffff"
android:gravity="center_horizontal|center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/spinner"
android:src="#drawable/ic_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/category_loading"
android:text="#string/loading"
android:textColor="#000"
android:padding="#dimen/activity_padding"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
This is the method I'm using to show/hide:
private void hideOrShowLoading(final boolean show) {
final ViewGroup spinnerWrapper = (ViewGroup)ll.findViewById(R.id.spinner_wrapper);
final View spinner = ll.findViewById(R.id.spinner);
if (show) {
spinnerWrapper.setVisibility(View.VISIBLE); // Not working after being set to GONE previously
final Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.rotate);
rotation.setFillAfter(true);
spinner.startAnimation(rotation);
} else {
spinnerWrapper.setVisibility(View.GONE);
spinner.clearAnimation();
}
}
Any tips? Could it have something to do with the ListView above it having a height of 0 and a weight of 1?
Thanks
Update
I also tried the following after the if (show) block, with no luck:
listview.invalidate();
spinnerWrapper.invalidate();
ll.invalidate();
ll.requestLayout();
ll is the LinearLayout that contains both.

While I believe this is caused by the layout_weight=1 property, I wasn't able to properly fix this.
The following hack did work. Basically, I'm surrounding the spinnerWrapper in another linear layout which is always visible.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/noconnectionll"
tools:visibility="visible"
android:visibility="gone"
android:padding="#dimen/node_default_spacing"
android:background="#color/category_no_internet"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="#string/no_internet_short"
android:textColor="#fff"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/no_connection_retry"
android:text="#string/try_again"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ListView
tools:background="#d496d4"
android:dividerHeight="0dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<!-- Weird bug with layout_weight=1 on the listview above means we need this linearlayout -->
<LinearLayout
android:background="#0ca917"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/spinner_wrapper"
android:background="#a0ffffff"
android:gravity="center_horizontal|center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/spinner"
android:src="#drawable/ic_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/category_loading"
android:text="#string/loading"
android:textColor="#000"
android:padding="#dimen/activity_padding"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Related

Custom TitleView with Description and Preview Image Android TV (FireTV)

I am trying to build my first Amazon Fire TV app using Android Lean back library. I want to customise the BrowseFragment to look like the image shown below.
I tried setting a custom layout as below.
#Override public View onInflateTitleView(LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
View title = inflater.inflate(R.layout.custom_title_view, parent, false);
titleImageView = (AppCompatImageView) title.findViewById(R.id.title_content_thumbnail);
return title;
}
but the resulting layout is showing as shown below, with a transparent TitleView and the list rows are showing below that. Please suggest a better approach to make the UI looks similar to the first image. Couldn't find anything that could implement this.
So, I have solved this somehow. My activity_main.xml looks like this.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/default_background"
android:orientation="vertical"
>
<fragment
android:id="#+id/title_layout"
android:name="com.kalpnik.vrdevotee.fragment.MainTitleFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_weight="1"
/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#+id/title_layout"
android:layout_weight="1"
tools:deviceIds="tv"
/>
</LinearLayout>
In the FrameLayout I will load a fragment which extended from BrowseFragment, so this gives me the necessary rows.
And at the top, I am loading MainTitleFragment which is extended from Fragment and the layout looks like below.
fragment_main_title.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="#000000"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/icon_background"
android:orientation="vertical"
android:paddingTop="16dp"
>
<TextView
android:id="#+id/title_content_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
tools:text=""
android:textColor="#color/colorPrimaryDark"
android:textSize="28sp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/title_content_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp"
android:ellipsize="end"
android:text=""
android:textSize="15sp"
/>
</LinearLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
>
<android.support.v7.widget.AppCompatImageView
android:id="#+id/title_content_thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
<View
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="#drawable/transparent_bg"
/>
<View
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="bottom"
android:background="#drawable/transparent_bg_bottom"
/>
</FrameLayout>
</LinearLayout>
And this worked for me. Hope this helps.

Scrolling & Layout Problems with ExpandableListView

I am developing an app which needs a unscrollable header at the top, Scrollable ExpandableListView in the middle and then unscrollable footer at the bottom. see the image below
The problem is Scrollable property of ExpandableListView, when i expand parent view of the ExpandableListView, list scroll under footer, unscrollable, which is the problem. See below
here's the xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F2B1DBF3"
android:orientation="vertical" >
<include
android:id="#+id/callheader"
android:layout_alignParentTop="true"
layout="#layout/callerheader" />
<ExpandableListView
android:id="#+id/exSavedVoiceList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/callheader"
android:groupIndicator="#drawable/drawableanimation"
android:paddingLeft="10dp" >
</ExpandableListView>
<LinearLayout
android:id="#+id/llbottom"
android:layout_width="match_parent"
android:layout_height="50sp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#ff33b5e5"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/bSaveNewVoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff33b5e5"
android:contentDescription="#string/add_new"
android:drawableLeft="#drawable/setting"
android:drawablePadding="40dp"
android:text="#string/add_new"
android:textColor="#FFFFFF"
android:textSize="25sp" />
</LinearLayout>
If i put android:layout_below="#+id/exSavedVoiceList" in llbottom (LinearLayout), footer moves below if parent view is expanded.
Please provide a solution with a possible explaination.
// try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F2B1DBF3"
android:orientation="vertical" >
<include
android:id="#+id/callheader"
layout="#layout/callerheader" />
<ExpandableListView
android:id="#+id/exSavedVoiceList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_below="#+id/callheader"
android:groupIndicator="#drawable/drawableanimation"
android:paddingLeft="10dp"/>
<LinearLayout
android:id="#+id/llbottom"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#ff33b5e5"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/bSaveNewVoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff33b5e5"
android:contentDescription="#string/add_new"
android:drawableLeft="#drawable/setting"
android:drawablePadding="40dp"
android:text="#string/add_new"
android:textColor="#FFFFFF"
android:textSize="25sp" />
</LinearLayout>
</LinearLayout>
Please add android:layout_above="#+id/llbottom" to your expandablelistview. and don't add android:layout_below="#+id/exSavedVoiceList" to your llbottom layout.

Animate a layouts alpha

I have a layout that i am trying to animate. It initially has its visibility set to GONE with alpha 0.
I then use the following to animate it:
final LinearLayout layout = (LinearLayout) findViewById(R.id.main_info);
layout.setVisibility(View.VISIBLE);
layout.bringToFront();
final AlphaAnimation animation = new AlphaAnimation(0F, 0.8F);
animation.setDuration(time);
animation.setFillAfter(true);
layout.startAnimation(animation);
But nothing happends. I have used the same code with a progressBar and i get the result i want. Why isnt it working for my layout?
I am animating it to come in front of another layout (if it isnt already) to act as an information screen hence the bringToFront(). I would like to add that i have since deleted the bringToFront() and there is no change. So the problem is nothing to do with that.
Edit: XML Code
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/relative_6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<ImageView
android:id="#+id/img_custom5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_pic" />
<TextView
android:id="#+id/text_custom5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/img_custom5"
android:layout_alignRight="#id/img_custom5"
android:layout_alignTop="#id/img_custom5"
android:gravity="left"
android:text="#string/text_custom5"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/main_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"
android:background="#color/color_black"
android:orientation="vertical"
android:visibility="gone" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:minHeight="50dp"
android:minWidth="50dp"
android:src="#drawable/arrow_up" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:text="#string/pleasewait"/>
</LinearLayout>
</RelativeLayout>

Vertical line not draw

I'm trying to draw a centered vertical line in a scrollview. I have got two galaxy 2s one with the Android version 4.2.2 and the other with the version 2.3.7.
My results as far only works under the android version 4.2.2
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<View
android:layout_width="4dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#000000" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test text" />
</RelativeLayout>
</FrameLayout>
</ScrollView>
While using the android version 2.3.7 the view (line in the middle) is no draw.
Does anyone knows whats the problem running android 2.3.7?
I didn't find a xml only solution.
My xml looks like. Note that the view has a fixed height which will be replaced in the activity.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/ManualStartTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Start" />
<RelativeLayout
android:id="#+id/CenterRelativLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ManualNoCardTableRow" >
<View
android:id="#+id/ManualTopGrayLine"
android:layout_width="1dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:background="#000000" />
<TextView
android:id="#+id/ManualStepTreeHeaderTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ManualStepTreeButton"
android:layout_marginLeft="3dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="#+id/ManualTopGrayLine"
android:gravity="right"
android:text="3) Verifizieren" />
<TextView
android:id="#+id/ManualStepTreeBodyTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/ManualStepTreeHeaderTextView"
android:layout_below="#+id/ManualStepTreeHeaderTextView"
android:layout_marginLeft="3dp"
android:text="Lorem alfpha alsda a,si ljkasoi kjasbas asdop1 ,aspo9ij aslkdja9s oaisdjas0pd oasdn0p9m asd0p9" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/CenterRelativLayout"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:orientation="vertical" >
<!-- some other content -->
</LinearLayout>
</RelativeLayout>
</ScrollView>
the xml generates the following view.
If you want to have a dynamically height of you line (view) you can add the following method to your activity. Which will set the height of the line to the same height as the RelativeLayout.
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus == true) {
View manualTopGrayLine = findViewById(R.id.ManualTopGrayLine);
RelativeLayout rlayout = (RelativeLayout) findViewById(R.id.CenterRelativLayout);
RelativeLayout.LayoutParams layoutParams = (android.widget.RelativeLayout.LayoutParams) manualTopGrayLine.getLayoutParams();
layoutParams.height = rlayout.getHeight();
manualTopGrayLine.setLayoutParams(layoutParams);
}
}

Android, LinearLayout won't scroll

I am relatively new to android programing. Can anybody tell me why my ScrollView won't scroll?
My activity has implemented OnGestureListener for getting some touch information. But, I tried to disable onGestureListener and it still won't work.
It works outside of the SlidingDrawer. Is it possible to get it work inside of the SlidingDrawer?
I solved it by giving to ScrollView ID and then put that ID in SlidingDrawer android:content="#+id/content".
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="#drawable/pozadina_touchpad"
android:orientation="vertical" >
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:orientation="vertical" >
<SlidingDrawer
android:id="#+id/prosirenje"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:content="#+id/content"
android:handle="#+id/handle" >
<Button
android:id="#+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/gumb_slider"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/slider"
android:gravity="center"
android:onClick="nemaSkrola"
android:orientation="vertical" >
<Button
android:id="#+id/ico_povecalo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#drawable/ikona_povecalo" />
<Button
android:id="#+id/ico_desktop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#drawable/ikona_komp" />
<Button
android:id="#+id/ico_daljinski"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#drawable/ikona_play" />
<Button
android:id="#+id/ico_tipkovnica"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#drawable/ikona_tipka" />
<Button
android:id="#+id/ico_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#drawable/ikona_settings" />
</LinearLayout>
</ScrollView>
</SlidingDrawer>
</LinearLayout>
</LinearLayout>
give some value to scrollView's width and height and try like this
<ScrollView
android:id="#id/content"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
please change scrollview id like this:
android:id="#id/content"
please change handle button id like this:
android:id="#id/handle"
The containers (hierarchical parents) of the ScrollView have the following attribute set this way: android:layout_height="match_parent", which forces them to limit their content to the height of the activity (screen).
For your ScrollView to work, try to get the ScrollView to a higher hierarchical level, so that won't be constrained by its parent.

Categories

Resources