J'ai un TextView pour la description et l'autre pour l'étape actuelle « application pour recettes »chevauchement texte TextView lorsque l'orientation change
Lorsque j'ai changé l'orientation du dispositif de paysage et de revenir en mode portrait à nouveau ce problème Happen (texte dans TextView viennent comme un autre TextView pas même s'il y a un seul TextView et ce chevauchement arrive) voir les images ci-jointes.
Normal view before changing orientation
This when i go landscape and returned to portrait again
fichier Xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/playerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<ImageView
android:id="@+id/thumbImage"
android:layout_gravity="left"
android:paddingRight="15dp"
android:elevation="1dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:padding="16dp"
android:textSize="17sp"
android:text="intro"
android:freezesText="true"
android:gravity="center_horizontal"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.design.widget.FloatingActionButton
android:id="@+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_next"
android:layout_alignParentRight="true"
app:fabSize="auto" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_back"
app:fabSize="auto" />
<TextView
android:id="@+id/currentStep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="1/10"
android:textSize="20sp"/>
</RelativeLayout>
</LinearLayout>
code Java:
public class StepDetailsFragment extends android.app.Fragment implements View.OnClickListener {
ArrayList<Step> steps;
StepsAdapter adapter;
@BindView(R.id.description)
TextView description;
@BindView(R.id.currentStep)
TextView current;
@BindView(R.id.next_button)
FloatingActionButton next;
@BindView(R.id.back_button)
FloatingActionButton back;
FragmentOneListener listener;
public int currentIndex;
@BindView(R.id.playerView)
SimpleExoPlayerView playerView;
SimpleExoPlayer player;
private boolean playWhenReady=true;
private long playbackPosition;
private int currentWindow;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.details_fragment, container, false);
ButterKnife.bind(this, root);
Bundle bundle = getArguments();
if (!bundle.containsKey("steps")) {
return root;
}
steps = bundle.getParcelableArrayList("steps");
currentIndex = bundle.getInt("current");
show();
back.setOnClickListener(this);
next.setOnClickListener(this);
return root;
}
@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.back_button) {
currentIndex--;
show();
} else if (id == R.id.next_button) {
currentIndex++;
show();
}
}
public void show() {
if (currentIndex <= 0) {
back.setVisibility(GONE);
} else {
back.setVisibility(View.VISIBLE);
}
if (listener != null) {
listener.setCurrent(currentIndex);
}
if (currentIndex >= steps.size() - 1) {
next.setVisibility(GONE);
} else {
next.setVisibility(View.VISIBLE);
}
description.setText(steps.get(currentIndex).getDescription());
current.setText((currentIndex + 1) + "/" + steps.size());
}
Votre activité est recréée en rotation. Le gestionnaire de fragments stocke le fragment d'origine dans l'état de l'instance, mais je suppose que vous ajoutez un nouveau fragment dans onCreate() de l'activité. Vous avez donc le fragment restauré et le nouveau fragment les uns sur les autres. Peut-être ajouter un nouveau fragment seulement si savedInstanceState est null. –
Merci! Cela a fonctionné, le problème était avec l'état d'activité. –
Je l'ai ajouté comme réponse –