有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java TextView在FragmentStateAdapter中不显示全文

我想实现一个带有图像和文本的ViewPager,但是,有时文本显示不完全

    <ImageView
        安卓:id="@+id/presentation_art"
        安卓:layout_width="match_parent"
        安卓:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        安卓:id="@+id/presentation_title"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:text="@string/presentation_title"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/presentation_art"/>

    <TextView
        安卓:id="@+id/presentation_content"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:text="@string/presentation_content"
        安卓:gravity="center"
        安卓:maxWidth="256dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/presentation_title" />

但是,演示内容,有时有2行文本,有时有3行,但每种情况下只显示2行

public class PresentationPagesAdapter extends FragmentStateAdapter {
    private static final int size = 3;

    public PresentationPagesAdapter(Fragment fragment) {
        super(fragment);
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return new PresentationPage(position);
    }

    @Override
    public int getItemCount() {
        return size;
    }

    public static class PresentationPage extends Fragment {
        private ComponentPresentationBinding binding;
        private final int n;

        public PresentationPage(int n) {
            this.n = n;
        }

        @Nullable
        @Override
        public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            binding = ComponentPresentationBinding.inflate(inflater, container, false);
            return binding.getRoot();
        }

        @Override
        public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
            super.onViewCreated(view, savedInstanceState);

            Context context = getContext();
            if (context != null) {
                Presentation presentation = new Presentation(context, n);
                binding.presentationContent.setText(presentation.getContent());
            }
        }
    }
}

我已经在没有ViewBinding的情况下尝试过了,但是它抛出了相同的结果

我该怎么办

请帮助我:(

(我不会说英语,只是在学习,我想我会重复一些单词,所以不要评判我呵呵)


共 (0) 个答案