I have a small animation in my app, that in the end of it changes the location parameters of a ListView i.e. it comes a bit lower than when it started (It starts as full screen and after a button press, its sliding down a little to reveal something beneath it, on the top of the screen). By pressing on the list I can see that its parameters realy changed and its location really changed. Now, if the SlidingDrawer is getting opened at that point, the layout gets rearranged and the list is back to full screen. Why is that?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.softtechnics.mobuynet"
android:id="#+id/coupon_list_layout"
style="#style/FillParent"
android:orientation="vertical" >
<include
android:id="#+id/filter_tab"
android:layout_width="match_parent"
android:layout_height="34dp"
android:layout_below="#+id/action_bar"
layout="#layout/filter" />
<com.softtechnics.mobuynet.gui.components.ListArr
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/footer"
android:layout_below="#+id/action_bar">
</com.softtechnics.mobuynet.gui.components.ListArr>
<com.softtechnics.mobuynet.gui.components.ActionBar
android:id="#+id/action_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<ProgressBar
android:id="#+id/progress"
style="#style/WrapContent"
android:layout_centerInParent="true"
android:visibility="gone" />
<com.softtechnics.mobuynet.gui.components.Footer
android:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignTop="#+id/textView1" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="113dp"
android:layout_alignParentBottom="true"
android:visibility="invisible" />
Footer is my SlidingDrawer.
Thanks!
You have to change listview properties when the animation ends. Also you should remember actual state of this view and update it in onResume method.
Related
i have a basic layout which contains some views. When there is a network connection a RecyclerView is shown. When the user swipes to refresh and there is no connection a button and a textview, which are inside the basic layout invisible at first place, become visible. The problem is that the button is not clickable in devices with Android version < Lollilop.
basic_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listSurveysRlt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.rey.material.widget.TextView
android:id="#+id/codeDescTtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/code_dest_txv_padding_bottom"
android:visibility="gone"
android:gravity="center"
android:layout_above="#+id/sRetryBtn"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textSize="#dimen/code_dest_txv_text_size"
android:textColor="#android:color/black"
android:textStyle="bold" />
<com.rey.material.widget.Button
android:id="#+id/sRetryBtn"
android:layout_width="#dimen/action_btn_width"
android:layout_height="#dimen/action_btn_height"
android:text="#string/retry"
android:textColor="#android:color/white"
android:background="#drawable/ripple_drawable"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:visibility="gone" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeRefreshLlt"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/completedSurveysRcV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/surveys_rcv_margin_top" />
</android.support.v4.widget.SwipeRefreshLayout>
<ImageView
android:id="#+id/noSurveysImv"
android:layout_width="#dimen/no_surveys_imv_width"
android:layout_height="#dimen/no_surveys_imv_height"
android:src="#drawable/no_surveys"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/no_surveys_imv_margin_top"
android:visibility="gone"
android:contentDescription="#string/ongoing" />
<com.rey.material.widget.TextView
android:id="#+id/noSurveysTxv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/noSurveysImv"
android:text="#string/no_completed"
android:textSize="#dimen/no_surveys_txv_text_size"
android:textColor="#color/no_surveys_txv_color"
android:visibility="gone"
android:layout_centerHorizontal="true" />
</RelativeLayout>
the method which transforms the corrensponding views from visible to invisible and vice versa:
private void onErrorBackgroundView(int code) {
listSurveysRlt.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.view_color));
completedSurveysRcV.setVisibility(View.GONE); //RecyclerView
codeDescTtv.setVisibility(View.VISIBLE); //TextView
retryBtn.setVisibility(View.VISIBLE); //not clickable button
codeDescTtv.setText(getResources().getString(inputValidationCodes.get(code)));
}
After some digging i found out the reason behind this strange behavior of the framework. The culprit was the SwipeRefreshLayout that blocked ui clicks ,so by setting the visibility of this layout to gone every time the user swipes the screen and restore the visibility when connection is available solved the issue. If anyone knows why this was happening in versions < Lollipop, it would be much helpful.
I'm writing an application and have come across a bit of an issue.
When working with a layout file, I have a 2 RelativeLayouts inside of a ViewFlipper.
The idea is that this page in particular is a welcome screen. The first RelativeLayout "welcomes" you to the app, and upon pushing a button, the user is led to the second RelativeLayout. In this layout there is a search bar that will allow the user to search for a certain criteria (specific to the app, not important) then display the results in a ListView.
Everything works correctly, but displaying the ListView seems to have some problems. The adapter is set properly, and I tested the method on another ListView in a test layout, and it worked fine. However something seems wrong with the ListView in the RelativeLayout. Here is the layout code
activity_welcome.xml
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/welcomeFlipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:animateLayoutChanges="true"
android:background="#color/white"
tools:context="com.jacemcpherson.announcer.WelcomeActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:padding="40dp">
...
<!-- This code irrelevant, all's well :) -->
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="#color/white"
android:padding="40dp">
<TextView
android:id="#+id/textFirstThingsFirst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textYouNeedToSearch"
android:layout_centerHorizontal="true"
android:text="#string/first_things_first"
android:textColor="#color/app_color"
android:textSize="32sp" />
<TextView
android:id="#+id/textYouNeedToSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="center"
android:text="#string/you_need_to_search_for_your_school"
android:textColor="#color/black"
android:textSize="18sp" />
<EditText
android:id="#+id/schoolSearchEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textYouNeedToSearch"
android:hint="#string/search_hint" />
<ProgressBar
android:id="#+id/searchListProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/schoolSearchEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:visibility="gone" />
<!-- This is the problem area -->
<ListView
android:id="#+id/searchResultsList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/schoolSearchEditText" />
</RelativeLayout>
</ViewFlipper>
I'm setting the adapter works like normal, but just in case I missed something, here's the line of code for that...
mListView.setAdapter(new ArrayAdapter<String>(
mContext,
android.R.layout.simple_list_item_1,
result // this is the array of results to be displayed in the list.
));
Thank you for your help, if I've missed something that in some way makes this unanswerable without further information, please let me know.
Change the layout_height from wrap_content to either match_parent or fill_parent.
This is explained very well by this answer.
What I am trying to do is, using the viewpager, create a photo album that when the user slides to next/previous, the opacity(Alpha) of the current image decreases and the opacity of the next/previous increases based on the sliding progress. The point is to give the impression that all the images are stacked and that they just fade from beneath the current picture. However, the title of the image, shows from left or right as a normal viewpager would do. Any ideas ?
My page fragment layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ImageView
android:id="#+id/slider_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
/> <!-- #FFF #000 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/slider_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="-80dp"
android:text="All-in-one"
android:textColor="#FFF"
android:textSize="32sp" />
<TextView
android:id="#+id/slider_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="image desc"
android:textColor="#FFF"
android:textSize="14sp" />
</LinearLayout>
You need to implement a PageTransformer similar to the examples here: http://developer.android.com/training/animation/screen-slide.html#depth-page
The extra step you need to do, is when you get the View in the pageTransform() method you need to get the Views you want to animate - ImageView in your case (using view.findViewById(R.id.slider_image)) and change the alpha value.
Sorry if the title isn't really clear but I don't know what the effect is called. It will get clear with some screenshots..
I have a homescreen with a search container on the top and a list of houses at the bottom.
The whole homescreen is a scrollview and when the 'Panden in uw buurt' textview passes the top off the screen I want it to be fixed.
start screen:
what I want to achieve if user scrolls down:
This is my xml layout:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
android:id="#+id/quick_search_view"
layout="#layout/view_quick_search"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/quick_search_view"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/house1" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/house2" />
</LinearLayout>
<View
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_below="#+id/quick_search_view"
android:layout_marginLeft="7dp"
android:background="#drawable/triangle_indicator"
android:rotation="180" />
</RelativeLayout>
follow the steps-
Exclude 'Panden in uw buurt' from your "#layout/view_quick_search".[Header also if its not actionBar]
Put it below "#+id/quick_search_view".
set/add Listeners for Scrolling.
OnScroll set visibility of "#+id/quick_search_view" gone/visible OR set
translate animation.
I found the solution : here
The stickyfragment and observableScrollView did the job!
I've got an activity layout specified in an XML file - activity_intro.xml - and I'm trying to create another one that is similar but slightly different - that's going to be activity_instructions.xml.
The Intro activity has a 9patch image at the bottom of the screen that is supposed to stay there and only adjust to different widths of the screens.
The Instructions activity is supposed to contain the same image but above 2 more buttons - all three of these views need to be always located at the bottom of the screen.
activity_intro.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"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/home_background" >
<LinearLayout
style="#style/Activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/introAnimationImageView"
android:layout_width="152dip"
android:layout_height="176dip"
android:layout_gravity="center_horizontal"
android:contentDescription="#string/intro_animation_content_description"
android:src="#drawable/animation_intro01" />
<TextView
android:id="#+id/introTextViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/intro_title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/introTextViewSubtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/intro_subtitle"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/introButtonLoginSignup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="#string/intro_button_label_login_signup" />
<Button
android:id="#+id/introButtonInstructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/introButtonLoginSignup"
android:text="#string/intro_button_label_instructions" />
<Button
android:id="#+id/introButtonReportAnonymously"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/introButtonLoginSignup"
android:layout_centerHorizontal="true"
android:text="#string/intro_button_label_report_anonymously" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:contentDescription="#null"
android:scaleType="fitXY"
android:src="#drawable/footer_cityscape" />
</LinearLayout>
Result:
Since I've got working code for Intro, I wanted to make Instructions follow its example but the layout_weight property isn't behaving as expected. First of all, I was only trying to put in the 2 buttons and leave out the image:
<?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:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="0.1"
android:background="#drawable/home_background" >
<LinearLayout
style="#style/Activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/instructionsTextViewTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/instructions_title_1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<ImageView
android:id="#+id/instructionsImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/instructions_image_content_description"
android:src="#drawable/forms" />
<TextView
android:id="#+id/instructionsTextViewDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/instructions_description_1"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<Button
android:id="#+id/instructionsButtonPrevious"
style="#style/ButtonPrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="#string/instructions_button_label_previous" />
<Button
android:id="#+id/instructionsButtonNext"
style="#style/ButtonNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="#string/instructions_button_label_next" />
</RelativeLayout>
</LinearLayout>
This only worked when I set the layout_weight of the bottom RelativeLayout to 1 (instead of 0) and for the ScrollView 0.1 (instead of 1). If I used the original values the RelativeLayout would take up all the screen. Could anyone explain to me why that is?
I also tried googling the issue and noticed people would suggest to set layout_height to 0dip which I tried but it also didn't work as expected.
Secondly, I tried adding the already mentioned ImageView to the bottom RelativeLayout. This, however, basically displays only the ImageView and not the buttons - or one of the buttons is on top of the image (hiding it). Why is that? Don't I specifically set the buttons to be placed below it?
What should the code look like in order for it to be doing what I expect it?
Further explanation:
Below are images that should help indicate what exactly I want to achieve. The green bits are the ScrollViews - I added them because Android devices tend to have diverse screen sizes. Their purpose is to present the content properly independently of the screen size, i.e. if the screen is small, the user will be able to scroll that part to read the entire text and view the image.
The red bit on the left (Intro) shows the ImageView that is supposed to always be at the bottom of the screen; it'll always be there, visible, and it's the green bit above it that will be movable.
If you take a look at the red bit on the right (Instructions), there's a Next button that's covering the image with the lorry/truck that was visible in the Intro screenshot. Now that's wrong - there should be 2 buttons BELOW the image, as seen on the last screenshot (the 2 blue rectangles).