In the application, when I upload data, I want to display a textView with an animation of such a plan, like: -> Loading .. -> Loading ...-- Loading. Roughly speaking, to add points, and so on the cycle, until the data from the server comes, and the adapter is not filled with them. Then textView from the fragment. Question: Is it possible to somehow lay this "animation" through xml?

  • Well, since, it seems, such an attribute is mute in the xml View, then, as you can see, it is simply impossible. The only thing that comes to mind is to write your own view with this attribute) - YuriySPb
  • @Yuriy SPb =) Apparently you have to do so. I thought there is a simpler solution - Android Android

1 answer 1

Maybe someone will need. Did this: Created your object

 public class LoadingTextView extends LinearLayout { private TextView loading; private LinearLayout layout; public LoadingTextView(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = layoutInflater.inflate(R.layout.loading_message, this); loading = (TextView) view.findViewById(R.id.loading); layout = (LinearLayout) view.findViewById(R.id.layout); } public void show() { layout.setVisibility(VISIBLE); startAnimate(); } public void hide() { layout.setVisibility(GONE); } protected void startAnimate() { Handler handler = new Handler(); for (int i = 200; i <= 600; i = i + 200) { final int finalI = i; handler.postDelayed(new Runnable() { @Override public void run() { if (layout.getVisibility() == View.GONE) { return; } if (finalI % 600 == 0) { loading.setText("Loading..."); startAnimate(); } else if (finalI % 400 == 0) { loading.setText("Loading.. "); } else if (finalI % 200 == 0) { loading.setText("Loading. "); } } }, i); } } } 

Here is his markup

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <TextView android:id="@+id/loading" android:layout_width="70dp" android:layout_height="wrap_content" android:textColor="@color/main_dark" android:textSize="14sp" /> </LinearLayout> 

In the fragment we put this way

 <com.roadlavaboy.application.core.LoadingTextView android:id="@+id/loadingTextView" android:layout_width="wrap_content" android:layout_centerInParent="true" android:layout_height="wrap_content"/> 

Well, management

  LoadingTextView loadingTextView = (LoadingTextView) rootView.findViewById(R.id.loadingTextView); loadingTextView.show(); 

It seems that everything looks fine.