gpt4 book ai didi

java - 如何在运行时显示多个图像(换行到下一行)

转载 作者:行者123 更新时间:2023-12-02 01:27:47 24 4
gpt4 key购买 nike

我有一个相当奇怪的应用程序,我将在运行时获取单词/符号,但不会提前知道它们。我需要显示它们,并在文本太宽而无法显示时自动换行。

我有点不确定我应该在功能上使用什么布局,但任何提示将不胜感激。如果我可以将它们添加到卡片 View 中并让它整理包装,那就太好了。有办法做到这一点吗?

下面的代码应该显示“这是一个在运行时动态组合的句子”。

example output

activity_main.xml

<?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"
tools:context=".MainActivity">

<android.support.v7.widget.CardView
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="40dp"
android:layout_centerHorizontal="true"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="1.9"
app:contentPadding="13dp"
>


<LinearLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:orientation="horizontal">

</LinearLayout>

</android.support.v7.widget.CardView>

</android.support.constraint.ConstraintLayout>

MainActivity.java

        LinearLayout ll = (LinearLayout)findViewById(R.id.layout);

ImageView ivThis = new ImageView(MainActivity.this);
ivThis.setImageResource(R.drawable.word_this);
ll.addView(ivThis);

ImageView ivIs = new ImageView(MainActivity.this);
ivIs.setImageResource(R.drawable.word_is);
ll.addView(ivIs);

ImageView ivA = new ImageView(MainActivity.this);
ivA.setImageResource(R.drawable.word_a);
ll.addView(ivA);

ImageView ivSentance = new ImageView(MainActivity.this);
ivSentance.setImageResource(R.drawable.word_sentance);
ll.addView(ivSentance);

ImageView ivPut = new ImageView(MainActivity.this);
ivPut.setImageResource(R.drawable.word_put);
ll.addView(ivPut);

ImageView ivTogether = new ImageView(MainActivity.this);
ivTogether.setImageResource(R.drawable.word_together);
ll.addView(ivTogether);

ImageView ivDynamically = new ImageView(MainActivity.this);
ivDynamically.setImageResource(R.drawable.word_dynamically);
ll.addView(ivDynamically);

ImageView ivAt = new ImageView(MainActivity.this);
ivAt.setImageResource(R.drawable.word_at);
ll.addView(ivAt);

ImageView ivRuntime = new ImageView(MainActivity.this);
ivDynamically.setImageResource(R.drawable.word_runtime);
ll.addView(ivRuntime);

最佳答案

I have a rather strange application where I will get the words/symbols at runtime and wont know them in advance. I need to display them and word wrap the text when it is too wide for the display.

听起来您正在寻找 RecyclerView动态显示数据(在运行时)。

关于java - 如何在运行时显示多个图像(换行到下一行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56614931/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com