Displaying Elements with a delay - android

How to make a delay on displaying elements in android studio i have 2 ImageView
<ImageView
android:id="#+id/a_letter"
android:background="#00000000"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="100dp"
app:srcCompat="#drawable/a_letter"
/>
AND
<ImageView
android:id="#+id/b_letter"
android:background="#00000000"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="100dp"
app:srcCompat="#drawable/b_letter"
/>
how to make the ImageView with the ID of a_letter load first when the layout is opened then make a 3 seconds delay before the ImageView with the ID of b_letter displayed?
is this a transition?

First make your image view gone in xml by adding:
<ImageView
android:id="#+id/b_letter"
android:background="#00000000"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="100dp"
app:srcCompat="#drawable/b_letter"
android:visibility="gone"/>
and then use a Handler:
ImageView bImageView = (ImageView) findViewById(R.id.b_letter);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
bImageView.setVisibility(View.VISIBLE);
}
}, 3000);

Related

ImageView background in not setting multiple times

I am working on an android project, in which I need to set ImageView
background (ascending icon and descending icon) multiple times. to do
this I am doing it with a clicking variable like:
sortBookedOnLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
pickUpImage.setBackgroundResource(R.drawable.ascending);
vouchredImage.setBackgroundResource(R.drawable.ascending);
cancledImage.setBackgroundResource(R.drawable.ascending);
if(Constant.bookedOn == 1) {
Log.d(TAG, "FliteronClick:1 ");
bookedonImage.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ascending_active));
// int ascending_active_b = R.drawable.ascending_active;
// bookedonImage.setBackgroundResource(ascending_active_b);
// bookedonImage.setImageDrawable(mContext.getResources().getDrawable( R.drawable.ascending_active));
// bookedonImage.setBackground(mContext.getResources().getDrawable(R.drawable.ascending_active));
// ivPickUpTxt.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ascending_active, 0);
Constant.bookedOn = 2;
}else if(Constant.bookedOn == 2){
Log.d(TAG, "FliteronClick:2 ");
bookedonImage.setImageDrawable(mContext.getResources().getDrawable(R.drawable.decending_active));
// bookedonImage.setImageResource(android.R.color.transparent);
// int decending_active_b = R.drawable.decending_active;
// bookedonImage.setBackgroundResource(decending_active_b);
// bookedonImage.setImageDrawable(mContext.getResources().getDrawable( R.drawable.decending_active));
// ivPickUpTxt.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.decending_active, 0);
Constant.bookedOn = 1;
}
}
}
});
And My Xml layout is just like:
<LinearLayout
android:id="#+id/sortBookedOnLayout"
android:orientation="horizontal"
android:background="#color/white"
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_weight="1.8"
android:layout_width="0dp"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/bookedOntxtLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/ivPickUpTxt"
style="#style/editTextTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/edittext_background"
android:drawableLeft="#drawable/cal2"
android:drawablePadding="10dp"
android:hint="#string/booked_on"
android:inputType="text"
android:maxLines="1"
android:padding="10dp"
android:textColor="#000000"
android:textCursorDrawable="#drawable/cursor_drawable"
android:textSize="#dimen/filter_text_size"
/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_weight=".2"
android:layout_width="0dp"
android:layout_height="match_parent">
<ImageView
android:id="#+id/booedOnImage"
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/ascending"
/>
</LinearLayout>
</LinearLayout>
Screenshot of my layout.
in this image i am going to click on BookedOn layout.
And my targetSdkVersion 25
I have tried it multiple ways as I commented but image icon is not
reflecting on imageView. any help will be appreciable.Thanks.
Try this:
qImageView.setBackgroundResource(R.drawable.thumbs_down);
and add android:scaleType:fitxy
<ImageView
android:id="#+id/booedOnImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitxy"
android:background="#drawable/ascending"/>
(or) Try programmatically
imgview.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
Here's a thread that talks about the differences between the two methods.
I Understand your problem...You are not set the width of the LinearLayout
<LinearLayout
android:layout_weight=".2"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<ImageView
android:id="#+id/booedOnImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/abc_btn_rating_star_off_mtrl_alpha"
/>
</LinearLayout>

Displaying placeholder for an image in recyclerview

I am trying to display a RecyclerView which initially loads a skeleton view before getting the data from API. In the below example, a simple imageview and a text is being displayed.
<android.support.v7.widget.CardView
android:id="#+id/cv_store_offer_display"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/img"
android:layout_width="match_parent"
android:layout_height="50dp"
android:scaleType="fitXY"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Foo FOO"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
I would like to know how to make my Recyclerview show the view even before the image/text is loaded. I am using Picasso to load image. mikepenz FastAdapter for displaying RecyclerView content.
I also tried to use a progressbar as mentioned in https://stackoverflow.com/a/12342168/371557. But progressbar was never shown even if the visibility is set to VISIBLE.
you can use something like
picasso.load(url)
.placeholder( R.drawable.place_holder )
.into(imageView);
<!--You Would Apply Like this-->
Picasso.load(url)
.placeholder( R.drawable.img_place_holder)
.into(imageView);
<!--Use ProgressBar-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/sliding_popup_window"
android:layout_below="#+id/bank_info_toolbar"
>
</android.support.v7.widget.RecyclerView>
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
//Your ProgressBar code
class Synch extends AsynchTask<void, void, void> {
public void onPreExecute() {
//your code
progressBar.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
}
}
public void doinBackground() {
//Your Code
}
public void onPostExecute() {
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}

Animating when re-positioning a view

As you can see in the attached code, linearLayoutLogo contains a ProgressBar and TextView and linearLayoutReading contains an ImageView and TextView. When linearLayoutReading is made visible the the two layouts reposition themselves around the center point due to android:layout_centerInParent="true".
How can I animate linearLayoutLogo so it shifts upwards to its new position prior to linearLayoutReading becoming visible? Please see the attached video for an example.
activity_main.xml
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true"
android:gravity="center">
<LinearLayout
android:id="#+id/linearLayoutLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="#+id/imageViewRLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_accessibility_black_24dp"
android:padding="8dp"/>
<TextView
android:id="#+id/textViewAppTitle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="34sp"
android:textColor="#CCFFFFFF"
android:text="AppName"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutReading"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="24dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/Base.TextAppearance.AppCompat.Large"
android:text="Reading from device"
android:textColor="#BF000000" />
<ProgressBar
android:id="#+id/progressBarSplash"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
style="#style/Base.Widget.AppCompat.ProgressBar.Horizontal"
android:paddingBottom="8dp"/>
</LinearLayout>
</LinearLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
public ProgressBar progressBarSplash;
public LinearLayout linearLayoutReading;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
linearLayoutReading = (LinearLayout)findViewById(R.id.linearLayoutReading);
linearLayoutReading.setVisibility(View.GONE);
new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
linearLayoutReading.setVisibility(View.VISIBLE);
progressBarSplash = (ProgressBar)findViewById(R.id.progressBarSplash);
progressBarSplash.setEnabled(true);
progressBarSplash.setIndeterminate(true);
}
}.start();
}
}
Tested it out on Android Studio. Just include android:animateLayoutChanges="true" in the top most LinearLayout (the one with centerInParent element).

Shared Element Transition in GridView Weird behavior

I'm using Shared Elements Transition between an imageView in a gridView adapter and an imageView in a details activity , but when i click on an item in the GridView the imageView dosen't start to animate from the right position it always starts under the original place, and when i hit back the image animates to the right place correctly so the glitch happens only when entering the new activity.
https://youtu.be/cprBHWPVNbk (i've slowed down the animation so that the glitch is clear).
In the BrowseFragment's OnCreate :
gridView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ImageView gridPoster = (ImageView) view.findViewById(R.id.movie_poster);
gridPoster.setTransitionName("poster" + position);
listener.onItemSelected(movie,gridPoster);
Then the BrowseActivity's listener starts the detailsActivtiy :
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation
(this, posterView,posterView.getTransitionName());
Intent detailsIntent = new Intent(this, MovieDetalisActivity.class);
detailsIntent.putExtra(getString(R.string.movie_details_extra_key), movie);
detailsIntent.putExtra("transition",posterView.getTransitionName());
ActivityCompat.startActivity(this, detailsIntent, optionsCompat.toBundle());
Then in the DetailsFragment's OnCreate :
ImageView poster = (ImageView) rootView.findViewById(R.id.poster);
poster.setTransitionName(getActivity().getIntent().getStringExtra("transition"));
GridViewItem layout :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/gird_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#4e585c"
android:clipChildren="false">
<ImageView
android:layout_width="match_parent"
android:layout_height="240dp"
android:id="#+id/movie_poster" />
<RelativeLayout
android:id="#+id/thumb_bottom_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:gravity="center_vertical">
<TextView
android:id="#+id/movie_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:fontFamily="sans-serif"
android:textColor="#aaa"
android:textSize="16sp"
/>
</RelativeLayout>
</LinearLayout>
Part of the DetailsView layout :
<android.support.v4.widget.NestedScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/scrollView"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:clipChildren="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.example.rashwan.popularmovies.MovieDetailsActivityFragment"
android:orientation="vertical"
android:focusableInTouchMode="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="310dp"
android:orientation="horizontal"
android:padding="10dp"
android:baselineAligned="false"
android:clipChildren="false">
<FrameLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:clipChildren="false">
<ImageView
android:layout_width="wrap_content"
android:minWidth="220dp"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:id="#+id/poster" />
</FrameLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:padding="5dp"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ReleaseDate"
android:id="#+id/release_date"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:padding="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UserRating"
android:id="#+id/user_rating"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:textAppearanceLarge"/>
</LinearLayout>
</LinearLayout>
And in my Theme i declared <item name="android:windowContentTransitions">true</item>i'm not using any custom animation although i tried some and i also tried to postpone the transition but nothing solved the problem.
I've found that the problem was that i'm using picasso library to load the images in the details fragment so i needed to use postponeEnterTransition(); in the details activity then in the details fragment i use getActivity().startPostponedEnterTransition(); to start the transition but only after the image is loaded using picasso.
Here's the code in the details fragment:
Picasso.with(getActivity()).load(posterUri).fit().into(poster, new Callback() {
#Override
public void onSuccess() {
poster.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
#Override
public boolean onPreDraw() {
if (isLollipop) {
poster.getViewTreeObserver().removeOnPreDrawListener(this);
getActivity().startPostponedEnterTransition();
}
return true;
}
});
}
Try putting your classes in manifest.AS

Android: Why does the update of the ProgressBar invalidates other views

I have this part of my layout:
<RelativeLayout
android:id="#+id/gameportView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_margin="3dp"
android:background="#drawable/bg_container_rounded" >
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="16dp"
android:layout_centerInParent="true"
android:progress="0" />
<com.pepotegames.spotthedifferences.DifferenceView
android:id="#+id/imageA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/progressBar"
android:layout_centerHorizontal="true" />
<com.pepotegames.spotthedifferences.DifferenceView
android:id="#+id/imageB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/progressBar"
android:layout_centerHorizontal="true" />
</RelativeLayout>
I have a ProgressBar and two custom Views. In my activity I have a countdown timer wich I use to update my ProgressBar and a TextView:
timer = new CountDownTimer(level.getTimeC(),1000){
public void onTick(long millisUntilFinished){
level.setTimeC(millisUntilFinished);
labelClock.setText(formatTime(millisUntilFinished));
//bar.setProgress((int) (1000 - ((level.getTimeC() * 1000)/level.getTimeT())));
bar.setProgress((int) (level.getTimeT() - level.getTimeC()));
if(!hurryFlag){
if(level.getTimeC() <= level.getTimeH()){
hurryFlag = true;
labelClock.setTextColor(getResources().getColor(R.color.hurry));
ImageView sprite = (ImageView) findViewById(R.id.level_sprite_clock);
sprite.setImageResource(R.drawable.sprite_clock_hurry);
//tic-tac sound
}
}
}
public void onFinish(){
labelClock.setText("00:00");
bar.setProgress((int) level.getTimeT());
gameOver(false);
}
};
The problem is that when I call bar.setProgress() it causes the redraw of imageA too (but not imageB). I've read through the layout drawing cycle and it says that the parent gets drawed first and then the childs in topdown order. Thats why I placed my ProgresBar first.
I really need to avoid setProgress to cause the invalidation of imageA. Any ideas of how can I achieve this?
Thank you!
Your imageA is placed above the progress bar.
Remove android:layout_above="#+id/progressBar and try.

Categories

Resources