I have a ScrollView with a TextView as it's child view, which changes it's span every second in Runnable called by MainActivity:
MainActivity:
// MainActivity's private members
private ConstraintLayout m_mainLayout;
private UnderlineSpan m_underlineSpan;
private SpannableStringBuilder m_spannableStringBuilder;
private Spannable m_spannableText;
private TextView m_textView;
private ScrollView m_scrollView;
private Runnable onUpdateTime = new Runnable()
{
#Override
public void run()
{
changeTextViewSpan();
m_mainLayout.postDelayed(onUpdateTime, 1000);
}
};
#Override
protected void onCreate(Bundle savedInstanceState)
{
m_textView = new TextView(this);
m_textView.setLayoutParams(
new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
m_scrollView.addView(m_textView );
m_spannableStringBuilder = new SpannableStringBuilder(Html.fromHtml(html)); // load long text from HTML file
m_textView.setText(m_spannableStringBuilder, TextView.BufferType.SPANNABLE);
m_spannableText = (Spannable) m_textView.getText();
}
private void changeTextViewSpan()
{
m_spannableText.setSpan(
m_underlineSpan,
startIndex,
endIndex,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
MainActivity layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ScrollView
android:id="#+id/largeTextScrollView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp">
</ScrollView>
<SeekBar
android:id="#+id/playbackSeekBar"
android:layout_width="251dp"
android:layout_height="30dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toTopOf="#+id/playbackControlButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/durationTextView" />
<ImageButton
android:id="#+id/playbackControlButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:onClick="onClick"
android:src="#drawable/ic_play_arrow_black_42dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageButton
android:id="#+id/volumeImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:src="#drawable/ic_volume_up_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/volumeBar"
app:layout_constraintTop_toBottomOf="#+id/playbackSeekBar" />
<SeekBar
android:id="#+id/volumeBar"
android:layout_width="94dp"
android:layout_height="0dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/playbackSeekBar" />
<TextView
android:id="#+id/currentPositionTextView"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="0:00"
app:layout_constraintBottom_toTopOf="#+id/playbackControlButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/transcriptScrollView" />
<TextView
android:id="#+id/slashTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="/"
app:layout_constraintBottom_toTopOf="#+id/playbackControlButton"
app:layout_constraintStart_toEndOf="#+id/currentPositionTextView"
app:layout_constraintTop_toBottomOf="#+id/transcriptScrollView" />
<TextView
android:id="#+id/durationTextView"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="0:00"
app:layout_constraintBottom_toTopOf="#+id/playbackControlButton"
app:layout_constraintStart_toEndOf="#+id/slashTextView"
app:layout_constraintTop_toBottomOf="#+id/transcriptScrollView" />
<ImageButton
android:id="#+id/trackImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:onClick="onClick"
android:src="#drawable/ic_visibility_off_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/volumeImageView"
app:layout_constraintTop_toBottomOf="#+id/playbackSeekBar" />
</android.support.constraint.ConstraintLayout>
Now, whenever I change TextView's span, the ScrollView stops scrolling, and after span is changed, ScrollView works correctly.
What I'm trying to achieve is to change the UnderlineSpan position of the long text which is loaded from the HTML file. The size of the text don't change, but it's long enough to put it into ScrollView.
Does anyone know what to do to make it scroll smoothly?
Thanks!
I am not really sure what you want to achieve.
But if you want a smooth scroll, you must set the height of your textview to a fixed size.
Then you can change textview content without changing its size every seconds.
This way the scroll must be smoothed.
Related
I have a TextView in which i am setting text dynamically(text length is not fixed ) and end of the text there is a icon,So My question is I want to show tooltip like tooltip arrow should be at top of info icon , as shown in attached image
You can follow this way
XML File
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/clMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:id="#+id/ivDone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:src="#drawable/ic_done_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/tvShipInBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Ship in Box($10 Extra per box)"
android:textColor="#E83535"
app:layout_constraintBottom_toBottomOf="#id/ivDone"
app:layout_constraintStart_toEndOf="#id/ivDone" />
<ImageView
android:id="#+id/ivInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:src="#drawable/ic_info_black_24dp"
app:layout_constraintBottom_toBottomOf="#id/ivDone"
app:layout_constraintStart_toEndOf="#id/tvShipInBox" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/clToolTip"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:background="#drawable/ic_tooltip_bg"
app:layout_constraintBottom_toTopOf="#id/clMain"
app:layout_constraintHeight_percent="0.075"
app:layout_constraintStart_toStartOf="#id/clMain"
app:layout_constraintWidth_percent="0.65">
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginHorizontal="8dp"
android:alpha="0.87"
android:text="A box increases an items volumetric weight and costs more."
android:textColor="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.6"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Java File
public class MainActivity extends AppCompatActivity {
ImageView ivInfo;
ConstraintLayout clToolTip;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ivInfo = findViewById(R.id.ivInfo);
clToolTip = findViewById(R.id.clToolTip);
ivInfo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ivInfo.setVisibility(View.INVISIBLE);
ivInfo.postDelayed(new Runnable() {
public void run() {
clToolTip.setVisibility(View.VISIBLE);
}
}, 7000);
}
});
}
}
ScreenRecording
I like the animation of the cardView at the top, but the views below arent animated and just snap in place. How can I animate them in a way that there is no overlapping? This is not a recyclerView, these are individual cardViews.
Code for the CardView at the top:
imageViewMuellExtend = (ImageView) root.findViewById(R.id.imageViewMuellExtend);
imageViewMuellExtend.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
muell_extend = (ConstraintLayout) root.findViewById(R.id.muell_extend);
cardViewMuell = (CardView) root.findViewById(R.id.cardViewMuell);
if(muell_extend.getVisibility() == View.GONE){
TransitionManager.beginDelayedTransition(cardViewMuell, new AutoTransition());
muell_extend.setVisibility(View.VISIBLE);
imageViewMuellExtend.setBackgroundResource(R.drawable.ic_keyboard_arrow_up_black_24dp);
} else {
TransitionManager.beginDelayedTransition(cardViewMuell, new AutoTransition());
muell_extend.setVisibility(View.GONE);
imageViewMuellExtend.setBackgroundResource(R.drawable.ic_keyboard_arrow_down_black_24dp);
}
}
});
XML Layout of the CardView:
<androidx.cardview.widget.CardView
android:id="#+id/cardViewMuell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:cardCornerRadius="8dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="16dp">
<ImageView
android:id="#+id/imageViewMuellIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="#drawable/ic_delete_black_24dp"
android:tint="#color/colorAccent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="Müll"
android:textColor="#000000"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="#+id/imageViewMuellIcon"
app:layout_constraintStart_toEndOf="#id/imageViewMuellIcon"
app:layout_constraintTop_toTopOf="#+id/imageViewMuellIcon"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="#+id/imageViewMuellExtend"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="16dp"
android:background="#drawable/ic_keyboard_arrow_down_black_24dp"
app:layout_constraintBottom_toBottomOf="#+id/imageViewMuellIcon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/imageViewMuellIcon" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/muell_extend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/imageViewMuellIcon">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="#string/info_muell"
android:textColor="#000000"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
Every CardView in this Fragment looks like this and the items are just renamed.
The first argument you're passing into TransitionManager.beginDelayedTransition is the sceneRoot. The transition will only affect views inside sceneRoot, nothing outside of it.
You're passing cardViewMuell as this argument, meaning the transition will animate views inside the clicked card, but none of the other cards. Try passing a sceneRoot that contains all of the cards.
I am attempting to add card views to a scroll view dynamically. so I am adding these cardviews to a linear layout which is situated inside a scrollview in my xml. However when I press the fab button I don't see anything. I don't know why. Is it something to do with layoutparams?
This is my create.java
public class create extends AppCompatActivity {
Button button;
Context context;
CardView cardview;
LayoutParams layoutparams;
TextView textview;
LinearLayout linearLayout;
ScrollView scrollView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create);
button = (Button)findViewById(R.id.button);
context = getApplicationContext();
linearLayout = (LinearLayout) findViewById(R.id.linearlayout1);
scrollView = (ScrollView)findViewById(R.id.scrollView1);
//TODO FAB BUTTON
FloatingActionButton floatingActionButton =
(FloatingActionButton) findViewById(R.id.fab);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
createCardViewProgrammatically();
}
});
}
public void createCardViewProgrammatically(){
CardView card = new CardView(context);
// Set the CardView layoutParams
LayoutParams params = new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
);
card.setLayoutParams(params);
// Set CardView corner radius
card.setRadius(9);
// Set cardView content padding
card.setContentPadding(15, 15, 15, 15);
// Set a background color for CardView
card.setCardBackgroundColor(Color.parseColor("#FFC6D6C3"));
// Set the CardView maximum elevation
card.setMaxCardElevation(15);
// Set CardView elevation
card.setCardElevation(9);
// Initialize a new TextView to put in CardView
TextView tv = new TextView(context);
tv.setLayoutParams(params);
tv.setText("CardView\nProgrammatically");
tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 30);
tv.setTextColor(Color.RED);
// Put the TextView in CardView
card.addView(tv);
// Finally, add the CardView in root layout
linearLayout.addView(card);
}
}
and this is my xml file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBackground"
android:minHeight="170dp"
tools:context=".create"
tools:layout_editor_absoluteY="81dp"
>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="438dp"
android:fillViewport="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="0dp">
<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"
tools:context="com.android_examples.cardviewprogrammatically_android_examplescom.MainActivity"
android:id="#+id/linearlayout1">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click here to Create CardView programmatically on Button click"
android:id="#+id/button"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="60dp"
android:layout_height="70dp"
android:layout_gravity="bottom|end"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="16dp"
android:layout_marginStart="8dp"
android:src="#android:drawable/ic_input_add"
app:backgroundTint="#color/colorCreate"
app:elevation="6dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:pressedTranslationZ="12dp"
android:tint="#color/colorBackground"/>
<View
android:id="#+id/subheading"
android:layout_width="match_parent"
android:layout_height="83dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="1dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_marginStart="1dp"
android:layout_marginTop="2dp"
android:background="#color/colorBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
/>
<View
android:id="#+id/view"
android:layout_width="320dp"
android:layout_height="1dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="76dp"
android:background="#color/colorText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="#+id/view2"
android:layout_width="320dp"
android:layout_height="1dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="28dp"
android:background="#color/colorText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:text="#string/done_label"
android:textColor="#color/colorText"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView4"
app:layout_constraintTop_toBottomOf="#+id/view2" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="128dp"
android:layout_marginRight="128dp"
android:layout_marginTop="8dp"
android:text="#string/aisle_label"
android:textColor="#color/colorText"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="#+id/view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view2"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginTop="5dp"
android:text="#string/qty_label"
android:textColor="#color/colorText"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="#+id/view"
app:layout_constraintEnd_toStartOf="#+id/textView4"
app:layout_constraintTop_toBottomOf="#+id/view2"
app:layout_constraintVertical_bias="0.7" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/item_label"
android:textColor="#color/colorText"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="#+id/view"
app:layout_constraintEnd_toStartOf="#+id/textView3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view2"
app:layout_constraintVertical_bias="1.0" />
</android.support.constraint.ConstraintLayout>
You need to specify the Orientation of your LinearLayout as VERTICAL
<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:orientation="vertical"
tools:context="com.android_examples.cardviewprogrammatically_android_examplescom.MainActivity"
android:id="#+id/linearlayout1">
I have two activities. The second activity has a textview that shows a string(about 600 words) from xml resources. When I want to start the second activity with a simple intent it shows the black screen for more than 30 seconds. Is this because of a long string? How i can solve this?
Intent intent = new Intent(Home.this, Text.class);
startActivity(intent);
Second avtivity:
public class Text extends AppCompatActivity {
TextView txt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text);
txt = findViewById(R.id.textView);
Typeface font = Typeface.createFromAsset(this.getAssets(), "B Roya.ttf");
txt.setTypeface(font);
}
}
and it's a layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryDark"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".Text">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_weight="20"
android:background="#drawable/janin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"
android:layout_weight="50"
android:paddingBottom="8dp">
<com.uncopt.android.widget.text.justify.JustifiedTextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/music"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:lineSpacingExtra="5dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:textColor="#android:color/white"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView" />
</ScrollView>
</LinearLayout>
Seems it was because of using below library and i replaced it with TextView then it solved:
com.uncopt.android.widget.text.justify.JustifiedTextView
I want to continuously show different text on text view which animates from left to right, waits on the center of the screen for 3 sec and animates outside of the screen and replaced by a new text which animates from left to right
I have included a textview inside a viewflipper.
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tv__inc_pre_sing__screen_title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#fff"
android:gravity="center"
android:text="PRACTICE"
android:textAllCaps="true"
android:textColor="#color/colorAccent"
android:textSize="16dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="#+id/rl__inc_pre_sing__tm_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#efff"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/tv__inc_pre_sing__screen_title">
<ImageView
android:id="#+id/tv__inc_pre_sing__quotation_mark"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginTop="12dp"
android:src="#drawable/ic_launcher_background"
app:layout_constraintTop_toTopOf="parent" />
<ViewFlipper
android:id="#+id/view_flipper"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:animateLayoutChanges="true"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/tv__inc_pre_sing__quotation_mark"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hiiiiii" />
</ViewFlipper>
<ImageView
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:src="#drawable/ic_launcher_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/view_flipper" />
</android.support.constraint.ConstraintLayout>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Click Me"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<View
android:layout_width="0dp"
android:layout_height="16dp"
android:background="#drawable/ic_launcher_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/rl__inc_pre_sing__tm_container" />
</android.support.constraint.ConstraintLayout>
MainActivity Code
public class Main6Activity extends AppCompatActivity {
private ViewFlipper mViewFlipper;
private int count = 0;
private TextView textView;
private ConstraintLayout rootContainer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main6);
mViewFlipper = findViewById(R.id.view_flipper);
textView = findViewById(R.id.tv);
rootContainer = findViewById(R.id.rl__inc_pre_sing__tm_container);
mViewFlipper.setAutoStart(true);
mViewFlipper.startFlipping();
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(rootContainer.getContext(), android.R.anim.slide_in_left));
mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(rootContainer.getContext(), android.R.anim.slide_out_right));
Resources resources = getApplicationContext().getResources();
final String[] textString = resources.getStringArray(R.array.teacher_messages);
new Thread() {
#Override
public void run() {
super.run();
try {
while (!isInterrupted()) {
Thread.sleep(3000);
runOnUiThread(() -> updateText(textString));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
public void updateText(String[] strings) {
if (count >= strings.length) {
count = 0;
}
textView.setText(strings[count]);
count++;
}
}
I guess the outanimation does not work as the textview length changes and I want to animate the constraint layout according to the textview height.
Not sure if this is the right reason.
The outAnimation of the view flipper does not work.
That's not how ViewFlipper works . the View flipper will only animate the view added to it .
Here's an example :
<ViewFlipper
android:id="#+id/viewFlipper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/loading"
android:autoStart="true"
android:flipInterval="5000"
android:inAnimation="#android:anim/slide_in_left"
android:outAnimation="#android:anim/slide_out_right">
<TextView
fontPath="fonts/benton_light.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/text1"
android:textColor="#color/white"
android:textSize="18sp" />
<TextView
fontPath="fonts/benton_light.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/text3"
android:textColor="#color/white"
android:textSize="18sp" />
<TextView
fontPath="fonts/benton_light.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/tex2"
android:textColor="#color/white"
android:textSize="18sp" />
</ViewFlipper>
Source
If that does not suit your needs . you can take a look at this solution. (Animating text changes in a TextView)